Re: Modeling 'user status' relationships

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Jun 29 2004 - 12:30:36 EDT

  • Next message: Andrus Adamchik: "Re: does cayenne support jdbc ARRAY?"

    Hi Robert,

    > I'm creating and registering a new UserStatus object
    > with each user, but that ends up throwing a duplicate primary key
    > exception.

    This is incorrect, and such exception is expected, as creating an object
    indicates an intent to create a NEW row in the DB, and you already have
    one for a given status.

    > Should I run a query to pull out the desired status from the
    > db and set the user status to /that/ object so that cayenne knows that
    > the desired UserStatus already exists in the UserStatus db entity?

    Yes, this is the way to go. Make sure you are using shared cache setting
    for such query -
    http://objectstyle.org/cayenne/userguide/fetch/result-caching.html

    Andrus

    > Hi,
    >
    > I have a User db entity/object and a UserStatus entity/object. The User
    > db entity has a status attribute that maps to a userStatus primary key.
    > There should be a finite number of rows in the UserStatus db entity
    > corresponding to the possible statuses a user may be set to. What's the
    > best way to set this up so that I can create a new user and set the
    > status to a certain status without cayenne trying to create a new status
    > row for that status?
    > eg:
    > possible user statuses:
    > normal and privileged.
    > Create user a and set status to normal. Create user b and set status to
    > normal; currently, I'm creating and registering a new UserStatus object
    > with each user, but that ends up throwing a duplicate primary key
    > exception. Should I run a query to pull out the desired status from the
    > db and set the user status to /that/ object so that cayenne knows that
    > the desired UserStatus already exists in the UserStatus db entity?
    > Thanks for any help!
    >
    > Robert



    This archive was generated by hypermail 2.0.0 : Tue Jun 29 2004 - 12:30:37 EDT