RE: Primary keys in expressions

From: Dave Merrin (dmerri..pasystems.co.uk)
Date: Tue Feb 07 2006 - 12:06:15 EST

  • Next message: Joshua Pyle: "Re: Query using foreign objects"

    Ah, that is what I was looking for. Yes, that does save needing the primary
    key mapped.

    Is this actually explained anywhere in the documentation? I've had another
    look through but can't see it (maybe I'm being blind).

    Cheers,

    Dave

    > -----Original Message-----
    > From: Cris Daniluk [mailto:cris.danilu..mail.com]
    > Sent: 07 February 2006 16:49
    > To: cayenne-use..bjectstyle.org
    > Subject: Re: Primary keys in expressions
    >
    >
    > On 2/2/06, Dave Merrin <dmerri..pasystems.co.uk> wrote:
    > > Hi,
    > >
    > > I want to be able to use a primary key in expressions. I see
    > there are two
    > > possible ways of doing this. The first is to prefix the column name with
    > > 'db:'. The second is to set up another mapping in my map file from an
    > > objentity to the existing dbentity.
    > >
    > > Which is the best way?
    >
    > If you map a key in the modeler, it means you are responsible for
    > setting it. Not recommended to do this just for searching.
    >
    > Why do you need to include the PK in an expression? Odds are you don't
    > need to. If you just need to resolve a PK to a DataObject, you should
    > use DataObjectUtils (or the new supercool SingleObjectQuery if you are
    > using 1.2).
    >
    > If not, you probably can use the DataObjects in your expressions,
    > rather than the PKs... i.e.
    >
    > Expression findPaintings =
    > Expression.matchExp(Painting.TO_ARTIST, artist);
    >
    > >
    > > And while I'm looking at this code why doesn't the generated
    > code for normal
    > > properties use the constants i.e.
    > >
    > > public static final String DESCRIPTION_PROPERTY = "description";
    > >
    > > public String getDescription() {
    > > return (String)readProperty("description");
    > > }
    > >
    >
    > Err... technically it does use the constant :) This is pre-compiled
    > code. On the first pass by the compiler, all instances of
    > DESCRIPTION_PROPERTY will be converted to "description". At runtime,
    > all strings are further interned so that there is only one
    > "description" string in the database... at least in this case. So, it
    > is really the same thing. And since its generated code, what do you
    > care? :)
    >
    > If its keeping you up at night, you could modify the template to use
    > the constant fairly easily.
    >
    > Cris
    >



    This archive was generated by hypermail 2.0.0 : Tue Feb 07 2006 - 12:08:01 EST