Re: Synch objEntity and dbEntity

From: John Martyniak (jmarty..x.netcom.com)
Date: Fri Oct 07 2005 - 10:42:21 EDT

  • Next message: John Martyniak: "Re: Synch objEntity and dbEntity"

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA256

    Jason,

    I agree in principle with your comments. However there are cases
    when this is not possible, specifically when converting an existing
    system.

    Also I don't believe that it is the place of a tool to determine
    standards and practices.

    - -John

    On Oct 6, 2005, at 10:12 PM, Jason Dwyer wrote:

    > Hi John,
    >
    > your best bet will be to not expose primary keys in the model. ORM
    > using
    > cayenne strives toward presenting an abstracted view of the underlying
    > data that hides the implementation of relationships from the api.
    >
    > if youre working with a clean slate: that is you're building the db
    > and
    > app at the same time, you should strive to arrange your data such
    > that the
    > primary keys are meaningless, typically a serial integer value.
    >
    > there are times in the application where you will want to reference
    > objects based on the details of the primary key, and for these, its a
    > simple matter of adding a method to your object entity subclass
    > which gets
    > the primary key value from the internal data for the object
    > matching the
    > row. something like this:
    >
    > pubic class MyObject extends _MyObject {// an extension of
    > CayenneDataObject
    > ...
    >
    > /** convenience method to expose the underlying primary key */
    > public int getPrimaryKey(){
    >
    >
    > if(getObjectId()!=null){
    > return DataObjectUtils.intPKForObject(this);
    > }
    > return -1;
    > }
    >
    > }
    >
    > you can also set up static factory methods which wrap around the
    > DataObjectUtils functionality to retrieve objects based on row primary
    > keys:
    >
    > public static MyObject getMyObjectByRowID(DataContext dc, int
    > rowID){
    >
    > return (MyObject)DataObjectUtils.objectForPK(
    > dc, MyObject.class, rowID);
    > }
    >
    > in this paradigm, you never want to actually set the primary key in
    > your
    > data objects directly: rely on the framework to set that up. you
    > instead
    > concern yourself with the Object relationships, and let cayenne
    > manage how
    > that will be persisted to the underlying db.
    >
    > if youre stuck on a legacy database with meaningful PK's, you might
    > need
    > to come up with a different strategy. DataObjectUtils is packed with
    > helpful stuff, i suggest you start from there.
    >
    > hope this helps,
    >
    > cheers,
    >
    > jd
    >
    >
    >> -----BEGIN PGP SIGNED MESSAGE-----
    >> Hash: SHA256
    >>
    >> To all,
    >>
    >> I think that this is a bug in the modeler, but I will toss it to the
    >> group first.
    >>
    >> So I have a primary key, that I would like to expose in the
    >> objEntity, if I add it, and then do some other work like make
    >> relationships. And then click the objEntity synch button the primary
    >> key disappears.
    >>
    >> Same thing hapens if I expose some other Ids, and then synch they
    >> disappear also.
    >>
    >> It seems to me that if I decide to expose something from the DbEntity
    >> into the objEntity it should remain that way.
    >>
    >> Or am I missing something.
    >>
    >> - -John
    >>
    >>
    >> -----BEGIN PGP SIGNATURE-----
    >> Version: PGP Desktop 9.0.1 (Build 2185)
    >>
    >> iQEVAwUBQ0WrlqF6YHs+0wZ7AQgiMAf+P0UYrR/qrP8GhQ6CtZ58W4zSsBL8VSEG
    >> bVgD3YOtOxl0zG3Wg5hax9VsEBCbER3fEalRHvsOW0sXqTjDyed7ZPtaB9G6+lKS
    >> rAc6502/98nOzTrQ5vyzHXaQtJdF3DMYd/R51C07sHtlfoXmJq/Obxl5y81qG3Zu
    >> FjMnukO0Jz5/Wv79ahSrkUCzN5VnE4gZOD2EhUy50aHY0cahg+0uAFZUgTec7KXT
    >> qG8YKbm+m36UHuQgJjUG7jpJuyA2ORJkMG0885Ps8JTqH1fsXDa1D4Sdq4pIh/S3
    >> uqLrlVhl9Uej6OyblYT8mR++DKkhhOGSWVVe191oTKSKmtKkJ/qiDQ==
    >> =uorR
    >> -----END PGP SIGNATURE-----
    >>
    >>
    >
    >
    >

    -----BEGIN PGP SIGNATURE-----
    Version: PGP Desktop 9.0.1 (Build 2185)

    iQEVAwUBQ0aJXKF6YHs+0wZ7AQi53gf/T6vG5ouFCu9KP1526gLQLrQvDS0umRsq
    urRFzb/zAGK8IQmF7BgqVGvVByaF0dRA+O3eFBdYtXGFD0X/LrGZNiqw6jaJWFiI
    8ZLWxlJCUxmPG+K7EiIxO1kINpFBzlX9z92Ww5N9++E10Ug1fO4laQ965Xxvadi0
    TeA0wl80aBOMj9AcnYa5vqHbDanu+z8I/m0ET4pB9vY/bfu26pPuE4UV4vHzz/c6
    HIgTaiPO47Szt9YsS7OiriCIXsJqXZOmgcFs2PkQl9g4flgzPwtMVKmok33Q/Ot9
    3ck6uj7nByj9WUjOtMuBuxLPVZ0jHU6Dx5QKuX28JwhpyMucIiB1Rw==
    =z+Oe
    -----END PGP SIGNATURE-----



    This archive was generated by hypermail 2.0.0 : Fri Oct 07 2005 - 10:42:38 EDT