openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Borkowski <>
Subject Persist on the same object fails after rollback
Date Wed, 21 Apr 2010 11:07:40 GMT


I'm trying to persist object after it was persisted and transaction was
rolled back.

I get following descriptive exception: 
"<openjpa-1.2.2-r422266:898935 nonfatal store error>
org.apache.openjpa.persistence.EntityExistsException: Attempt to persist
detached object "PersistentObjectDBImpl@f38cf0".  If this is a new instance,
make sure any version and/or auto-generated primary key fields are
null/default when persisting."

I'm using extended persistence context in a standalone application.
According to the manual after rollback in extended persistence context
persistent object should return to the "new/transient" state. But it looks
that it remains in "detached" state.

This behavior prevents from performing simple retry of transaction operating
on the same objects in case of some problems (ex. deadlock)

Following piece of code illustrates the problem:

    OpenJPAEntityManager manager = factory.createEntityManager();

    try {

      EntityTransaction transaction = manager.getTransaction();


      //assertFalse("Persistent object should be in New state after
rollback", manager.isDetached(notif));

      EntityTransaction transaction2 = manager.getTransaction();

      manager.persist(persistentObject);    // this line throws exception


I'm using OpenJPA 1.2.2 and pessimistic LockManager.

Best regards,
View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message