RE: Violation of PRIMARY KEY constraint

From: Leonardo R. Nunes (leonard..umersoft.com)
Date: Sat Nov 22 2003 - 17:22:23 EST

  • Next message: Andrus Adamchik: "Re: Violation of PRIMARY KEY constraint"

    Humm ... so ... I'll need to create a cache for the new objects then.
    I'll need do that because if I create one DataObject1 and before commit
    this DataObject1 create a DataObject2 with the same PK (Example: a
    driver's license number) I'll get a SQLException.

    I think that one kind of automatic PK checking would be a nice feature
    in Caynenne. Something like a query in the database plus a query in the
    objects that are only in memory.

    :)

    Regards,
    Leonardo.

    ********************
    Leonardo R. Nunes
    Sumersoft Tecnologia
    http://www.sumersoft.com

    -----Original Message-----
    From: Andrus Adamchik [mailto:andru..bjectstyle.org]
    Sent: sábado, 22 de novembro de 2003 17:53
    To: cayenne-use..bjectstyle.org
    Subject: Re: Violation of PRIMARY KEY constraint

    On Nov 22, 2003, at 2:47 PM, Leonardo R. Nunes wrote:

    > Does cayenne verify if a new object
    > (dataContext.createAndRegisterNewObject(“MyDataObjectClassName”))
    > violates a primary key ?
    > Or do I need query the database before create a newDataObject?
    >
    >
    > If I need query the database before … is there a way to query the
    > objects that was not “commited” ?

    Hi Leonardo,

    I don't know if you've been watching this thread over the past few
    days, but it answers all your questions:

    http://objectstyle.org/cayenne/lists/cayenne-user/2003/11/0067.html

    A short summary of this discussion:

    * If you have a meaningful PK that is also a property of a Java class,
    it is your responsibility to ensure that you assign a previously unused
    value. Otherwise Cayenne will do it for you.
    * SelectQueries are for database data only, so new uncommitted objects
    are not included in the query results.

    Andrus



    This archive was generated by hypermail 2.0.0 : Sat Nov 22 2003 - 16:19:31 EST