Re: How to retrieve the PK from the anArtist bean?

From: Craig Miskell (cmiskel..lbatross.co.nz)
Date: Mon Dec 30 2002 - 03:14:02 EST

  • Next message: martin ruff: "Re: How to retrieve the PK from the anArtist bean?"

    Just to add to Dirks comments: If you *really* *really* *really* need to
    access the pk and don't want to map it in the ObjEntity (which is a Good
    Thing (tm)), then you can ask any DataObject for it's ObjectId
    (getObjectId() is the method), from which you can get the IdSnapshot. the
    snapshot is a map, keys being the pk column name(s), value being the pk
    value.

    You can even pass a manually constructed ObjectId to a DataContext to get
    the object back (assuming the risk of an exception if the corresponding
    row doesn't exist in the db).

    But can I just reiterate what Dirk said about pk/fk's being relational
    artifacts. They really do just exist for the convenience of the database
    (nice, small, easily compared identifiers for a particular row). Even
    using them to identify objects in the database is dubious, and if there's
    any other column at all that is unique (or should be unique), then use
    that. It will save you a *LOT* of hassle long term. Believe me. Been
    there, done that, bought the t-shirt.

    Craig

     On Mon, 30 Dec 2002, Fan, Bill (AP - Australia) wrote:

    > Hi,
    >
    > I'm new to Cayenne. I've successfully set up the cayenne-web-app with tomcat
    > 4.1.17. My question is how to retrieve the ARTIST_ID in order to use it for
    > the "add painting" link? The exampe is using the artist's name for this
    > link. In the struts app I'm working on, I need to use the primary key to
    > associate the records.
    >
    > I noticed that there is no getter method for any PK column in all the java
    > class file generated.
    >
    >
    > Thanks!
    > Bill
    >
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Mon Dec 30 2002 - 03:10:36 EST