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

From: Dirk Olmes (dirk.olme..mx.de)
Date: Mon Dec 30 2002 - 01:24:59 EST

  • Next message: Craig Miskell: "Re: How to retrieve the PK from the anArtist bean?"

    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.

    You don't need the primary/foreign keys to add paintings to artists.
    This is done by cayenne automatically for you when you add a painting to
    the artist. You can verify that the framework does the right thing if
    you commitChanges on the DataContext with Level.DEBUG as argument and
    watch the generated SQL flying by.

    If you really need the primary/foreign key in your object model (which
    is a bad thing since pk/fk are only relational artefacts) you'll lose
    the auto-assignment capabilities of the framework. New primary keys for
    new objects won't be generated either. So try to stay away from pk/fk in
    your object model if you can.

    > I noticed that there is no getter method for any PK column in all the
    > java class file generated.

    That's because the ObjectEntity doesn't include any pk/fk columns from
    the DataEntity. If you include an attribute in your ObjectEntity that's
    mapped to your DataEntity's primary key you'll get accessors for that as
    well.

    HTH,

    -dirk



    This archive was generated by hypermail 2.0.0 : Mon Dec 30 2002 - 01:25:12 EST