Re: Retrieving via auto-generated keys

From: Eric Schneider (eri..entralparksoftware.com)
Date: Fri May 28 2004 - 08:28:36 EDT

  • Next message: Gentry, Michael: "RE: Retrieving via auto-generated keys"

    Mike,

    Once your action is invoked, you can refetch your object like this...

    Integer userId = new Integer(157);

    ObjectId objId = new ObjectId(User.class, "USER_ID", userId);
    User user = (User)dataContext.regesteredObject(objId );

    e.

    ----- Original Message -----
    From: "Mike Elliott" <mr..79.net>
    To: <cayenne-use..bjectstyle.org>
    Sent: Friday, May 28, 2004 7:46 AM
    Subject: Retrieving via auto-generated keys

    > I have a situation where I'm writing a web application. On some pages I
    need
    > to display, in a dropdown list, a subset of my users (around 750 total
    > users). That is, I need to generate something along the line of:
    >
    > <select name="selectedUser">
    > <option value="157">Biff Overbyte</option>
    > <option value="189">Steve Whotsit</option>
    > . . .
    > </select>
    >
    > What I'm talking about here is specifying as the 'value' attribute, the
    > generated integer primary key for the user, as a way of getting to the
    > full user record in the database. I can fetch this value from each user
    > instance by using the getObjectId() method, and properly generate the
    > "value=" portion of the option.
    >
    > The problem I have is what should I do in order to fetch the full record?
    > Basically, how do I go about fetching a row from the database where I know
    > the Cayenne-generated key value? I don't have a get() method for it (at
    > least directly) and it's unclear to me how to builld a query to access a
    > CayenneDataObject via its internally generated primary key.
    >
    > The overall problem I want to solve is how to display a subset of user
    names
    > from my user table as a dropdown list, then be able to fetch the
    > corresponding full User object via Cayenne. Maybe I'm going about this
    > completely wrong. If so, if anyone else has solved this problem, please
    let
    > me know.



    This archive was generated by hypermail 2.0.0 : Fri May 28 2004 - 08:28:27 EDT