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

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Feb 20 2008 - 14:59:14 EST

  • Next message: Andrus Adamchik: "Re: How to migrate from Hibernate to Cayenne?"

    Hmm... then I suspect a bug in handling that in DB-generated PK mode.
    We may need to reopen CAY-987, now that the scenario is clarified.

    Andrus

    On Feb 20, 2008, at 9:53 PM, Scott Anderson wrote:

    > I am using this function, and the latest changes from SVN:
    >
    > public static final void setIdx(CayenneDataObject obj, int pk) {
    > obj.getObjectId().getReplacementIdMap().put("idx", new
    > Integer(pk));
    > }
    >
    > Cayenne completely omits the PK field from its INSERT statement.
    >
    > I'm going to set up a new test environment and see if I can reproduce
    > the expected behavior to determine if it's my environment or Cayenne.
    >
    > Scott
    >
    > -----Original Message-----
    > From: Andrus Adamchik [mailto:andru..bjectstyle.org]
    > Sent: Wednesday, February 20, 2008 1:57 PM
    > To: use..ayenne.apache.org
    > Subject: Re: Specifying PK when creating a new object in DB
    > generated PK
    > mode
    >
    >> 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 - 15:00:05 EST