openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Curtis <curti...@gmail.com>
Subject Re: Error in EntityManager.persist () if the database already contains a row with id=0
Date Mon, 18 Feb 2013 19:58:35 GMT
Could you try adding an @Version field to your Entities?

Thanks,
Rick


On Mon, Feb 18, 2013 at 1:27 PM, Krishnaprasad Subbarao <
krishnaprasads@in.ibm.com> wrote:

> Hello,
>
> Following error occurs while I am trying to persist a record. The id field
> has  been assigned a default value (0) as per the guidelines.
>
> <openjpa-2.2.1-r422266:1396819 fatal store error> *
> org.apache.openjpa.persistence.RollbackException*: An object of type
> "com.ibm.wdp.bss.party.entity.PartyObject" with oid "0" already exists in
> this context; another cannot be persisted.
> FailedObject: com.ibm.wdp.bss.party.entity.PartyObject@7aa47aa4
>         at org.apache.openjpa.persistence.EntityManagerImpl.commit(*
> EntityManagerImpl.java:594*)
>         at com.ibm.test.jpa.JPAAddEntityTest.main(*
> JPAAddEntityTest.java:38*)
> Caused by: <openjpa-2.2.1-r422266:1396819 nonfatal store error> *
> org.apache.openjpa.persistence.EntityExistsException*: An object of type
> "com.ibm.wdp.bss.party.entity.PartyObject" with oid "0" already exists in
> this context; another cannot be persisted.
> FailedObject: com.ibm.wdp.bss.party.entity.PartyObject@7aa47aa4
>         at org.apache.openjpa.kernel.BrokerImpl.checkForDuplicateId(*
> BrokerImpl.java:5080*)
>         at org.apache.openjpa.kernel.BrokerImpl.persistInternal(*
> BrokerImpl.java:2653*)
>         at org.apache.openjpa.kernel.BrokerImpl.persist(*
> BrokerImpl.java:2573*)
>         at org.apache.openjpa.kernel.BrokerImpl.persist(*
> BrokerImpl.java:2556*)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(*
> SingleFieldManager.java:800*)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlush(*
> SingleFieldManager.java:621*)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlush(*
> SingleFieldManager.java:589*)
>         at org.apache.openjpa.kernel.SingleFieldManager.preFlush(*
> SingleFieldManager.java:505*)
>         at org.apache.openjpa.kernel.StateManagerImpl.preFlush(*
> StateManagerImpl.java:3028*)
>         at org.apache.openjpa.kernel.PNewState.beforeFlush(*
> PNewState.java:44*)
>         at org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(*
> StateManagerImpl.java:1042*)
>         at org.apache.openjpa.kernel.BrokerImpl.flush(*
> BrokerImpl.java:2114*)
>         at org.apache.openjpa.kernel.BrokerImpl.flushSafe(*
> BrokerImpl.java:2074*)
>         at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(*
> BrokerImpl.java:1992*)
>         at org.apache.openjpa.kernel.LocalManagedRuntime.commit(*
> LocalManagedRuntime.java:81*)
>         at org.apache.openjpa.kernel.BrokerImpl.commit(*
> BrokerImpl.java:1516*)
>         at org.apache.openjpa.kernel.DelegatingBroker.commit(*
> DelegatingBroker.java:933*)
>         at org.apache.openjpa.persistence.EntityManagerImpl.commit(*
> EntityManagerImpl.java:570*)
>         ... 1 more
>
> The reason for this issue I found is, if the database which this object
> being persisted, contains a row with primary key as 0, then adding new
> record fails. Seems a duplicate primary key check is done when default
> value (0) is assigned to the id attribute of type primitive long. A record
> with Primary Key value = 0 already exists, so duplicate primary key check
> fails.
>
> This zip file contains a sample code with which I was able to reproduce
> this error.
>
> Adding a row with id=0 before persisting any object throws the error
> mentioned above.
>
> I request all to help in resolving this issue. The id 0 has been in use
> for many days using hibernate. Hence we would like not to change this row
> in the database.
>
> Also would like to know if there is any config parameter to change the
> default value of the id from 0 to any other value.
>
>
>
> Thanks and Regards,
>
> *KRISHNAPRASAD SUBBARAO*
> Software Developer, Cloud Platform (BSS), Industry Solutions, India
> Software Lab
>
>


-- 
*Rick Curtis*

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message