RE: Simple retrieval of an object by PK

From: Gentry, Michael (michael_gentr..anniemae.com)
Date: Thu Jul 15 2004 - 16:54:59 EDT

  • Next message: Todd O'Bryan: "Re: Simple retrieval of an object by PK"

    Keep in mind that Cayenne is designed to shield you from database
    artifacts like primary keys (the modeler doesn't even map the keys into
    the entity by default, although you can add them). Most queries needed
    by actual users don't contain a primary key -- that is merely a database
    mechanism to allow joins to occur behind the scenes.

    If you find you must use a primary key to do your searches, consider
    putting static helper methods in the subclass of the entities where you
    needed it. Something like: public static MyEntity
    objectForPrimaryKey(int key). Of course, if you have compound keys or
    different key types, modify accordingly. You could also put together a
    utilities type package for this.

    Good luck!

    /dev/mrg

    -----Original Message-----
    From: Jonathan Carlson [mailto:Jonathan.Carlso..atun.com]
    Sent: Thursday, July 15, 2004 4:18 PM
    To: cayenne-use..bjectstyle.org
    Subject: Simple retrieval of an object by PK

    I gravitate towards powerful tools that make simple things simple and
    hard things possible. I know that Cayenne is in this category of
    tools, but I don't see any way to simply and quickly retrieve an
    instance by it's primary key -- something that should be very easy and
    concise.

    For example, when doing web apps this seems like a common use case:
    1) Display a list of instances that each have a link to an edit page.
    (For example, each link would include a ?pk=999 request parameter which
    is not visible on the HTML page.)
    2) When the link is clicked, the action class grabs the pk request param
    and does a quick lookup of the obect before rendering the edit page.

    There must be a straightforward simple API to get an object by its PK
    without having to do 6 lines of code to setup a query, expression,
    params, and execution. It's really easy to grab all instances of an
    ObjEntity, why shouldn't it be just as easy to grab one instance?

    (BTW, I think DataContext.refetchObject(ObjectId oid) is on the right
    track towards the simplicity I'm looking for, but that doesn't appear to
    fill the need)

    Thanks in advance for any tips you might have in this area. It's
    possible I just missed something, but I think I've read all the relevant
    documentation.

    Thanks again,

    Jonathan

    ************************************************************************
    *********
    This email and any files transmitted with it are confidential and
    intended solely for the use of the individual or entity to whom they
    are addressed. If you have received this email in error please notify
    the system manager.

    Katun Corporation -- Celebrating 25 Years of Service
    www.katun.com
    ************************************************************************
    *********



    This archive was generated by hypermail 2.0.0 : Thu Jul 15 2004 - 16:55:04 EDT