openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Krishnaprasad Subbarao <>
Subject Error in EntityManager.persist () if the database already contains a row with id=0
Date Mon, 18 Feb 2013 19:27:32 GMT

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 
"" with oid "0" already exists in 
this context; another cannot be persisted.
        at org.apache.openjpa.persistence.EntityManagerImpl.commit(
Caused by: <openjpa-2.2.1-r422266:1396819 nonfatal store error> 
org.apache.openjpa.persistence.EntityExistsException: An object of type 
"" with oid "0" already exists in 
this context; another cannot be persisted.
        at org.apache.openjpa.kernel.BrokerImpl.checkForDuplicateId(
        at org.apache.openjpa.kernel.BrokerImpl.persistInternal(
        at org.apache.openjpa.kernel.BrokerImpl.persist(
        at org.apache.openjpa.kernel.BrokerImpl.persist(
        at org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(
        at org.apache.openjpa.kernel.SingleFieldManager.preFlush(
        at org.apache.openjpa.kernel.SingleFieldManager.preFlush(
        at org.apache.openjpa.kernel.SingleFieldManager.preFlush(
        at org.apache.openjpa.kernel.StateManagerImpl.preFlush(
        at org.apache.openjpa.kernel.PNewState.beforeFlush(
        at org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(
        at org.apache.openjpa.kernel.BrokerImpl.flush(
        at org.apache.openjpa.kernel.BrokerImpl.flushSafe(
        at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(
        at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
        at org.apache.openjpa.kernel.BrokerImpl.commit(
        at org.apache.openjpa.kernel.DelegatingBroker.commit(
        at org.apache.openjpa.persistence.EntityManagerImpl.commit(
        ... 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 

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,

Software Developer, Cloud Platform (BSS), Industry Solutions, India 
Software Lab

View raw message