Re: Primary Key Access

From: Mike Kienenberger (mkienen..mail.com)
Date: Tue Oct 25 2005 - 11:42:29 EDT

  • Next message: Andrus Adamchik: "Re: Primary Key Access"

    > getItem_id()

    The reason for this is that you're outputting DbAttributes rather than
    ObjAttributes, and your DbAttribute is named "item_id". I can't
    think of an easy way to deal with this under cgen v1.1. You'll have
    to write velocity code to perform the transformation.

    I don't understand your second issue.
    classGen.Entity.DbEntity.PrimaryKey should only return the primary
    keys for that entity, so it's unclear to me why you'd be seeing
    foreign keys unless you've mistakenly marked them as primary keys in
    your model.

    On 10/25/05, Dave Merrin <dmerri..pasystems.co.uk> wrote:
    > Hi,
    >
    > sorry to bug you with another question. All your help has been great.
    >
    > I'm trying to modify the template for the class generation. I want to give
    > access to primary keys. I've added the following code to the template. It
    > works apart from getting a weird method name e.g. getItem_id(). Does anybody
    > know how to sort this so I get something like getItemId()?
    >
    > #if( $classGen.Entity.DbEntity )
    > #foreach( $idAttr in ${classGen.Entity.DbEntity.PrimaryKey} )
    > #set( $classGen.Prop = $idAttr.Name )## let controller know about current
    > property
    > /** Read-only access to PK */
    > public Integer get${classGen.cappedProp}() {
    > return (getObjectId() != null && !getObjectId().isTemporary())
    > ?
    > (Integer)getObjectId().getIdSnapshot().get(${classGen.propAsConstantName}_PK
    > _COLUMN)
    > : null;
    > }
    > #end
    > #end
    >
    > Unfortunately the same code is generated for foreign keys. I see from the
    > documentation I should have something more like below as a result. This
    > accesses the Artist to get the primary key from the artist. Does this mean
    > another query is made to get the artist? If so is there any way to get the
    > id's without accessing the artist? Also how do I differentiate in the
    > template between a primary key and a foreign key?
    >
    > /** Read-only access to FK */
    > public Integer getArtistId() {
    > Artist artist = getArtist();
    > return (artist != null)
    > ?
    > (Integer)artist.getObjectId().getIdSnapshot().get(Artist.ARTIST_ID_PK_COLUMN
    > )
    > : null;
    > }
    >
    > Thanks again for all the help on the previous issues.
    >
    > Dave
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Oct 25 2005 - 11:42:30 EDT