Re: Specifying PK when creating a new object in DB generated PK mode

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Feb 20 2008 - 13:56:52 EST

  • Next message: Thomas Bernhard: "How to migrate from Hibernate to Cayenne?"

    > Cayenne should not disregard user-made decisions: it isn't Cayenne's
    > responsibility to enforce PK integrity.

    It will not disregard the user decisions. If I understood correctly
    what you are trying to do, my recommendation would be this:

       MyObject object = context.newObject(MyObject.class);
       object.getObjectId().getReplacementIdMap().put("PK_COLUMN", value);

    When you said "PK is set through the ObjectID map", did you mean the
    API above or something else? AFAIK the approach above should work.

    Andrus

    On Feb 20, 2008, at 8:31 PM, Scott Anderson wrote:
    > It looks like there's no model that fits what I'd like to do. IMO, the
    > user should be able to specify the PK in DB-generated mode when either
    > the field is exposed, or the PK is set through the ObjectID map.
    > Cayenne
    > should not disregard user-made decisions: it isn't Cayenne's
    > responsibility to enforce PK integrity.
    >
    > -----Original Message-----
    > From: Aristedes Maniatis [mailto:ar..sh.com.au]
    > Sent: Wednesday, February 20, 2008 2:01 AM
    > To: use..ayenne.apache.org
    > Subject: Re: Specifying PK when creating a new object in DB
    > generated PK
    > mode
    >
    >
    > On 20/02/2008, at 9:51 AM, Scott Anderson wrote:
    >
    >> I am working an a request ticket system, similar to the one I'm using
    >> to enter this issue. I need to import requests from the old schema to
    >> the new schema, and the PKs must be specified while doing an import.
    >> When using the tool normally, the PKs must be database generated. Is
    >> there any way to do this?
    >
    > You can specify the key yourself easily:
    > http://cayenne.apache.org/doc/primary-key-generation.html
    >
    > But I can't see how you can guarantee you will not get collisions
    > between your two schemes. Maybe better to keep the old key in a
    > separate
    > field for reference purposes.
    >
    > Ari Maniatis
    >



    This archive was generated by hypermail 2.0.0 : Wed Feb 20 2008 - 13:57:35 EST