Hi Adam, I wasn't able to find the section of the user manual which says that new instances will be in the new/transient state after rollback. The nearest hit I could find was this one (section 2. The EntityTransaction Interface)
"Unless you are using an extended persistence context, committing or rolling back also ends the persistence context. All managed entites will be detached from the EntityManager." Unfortunately this has not been the case since OPENJPA-118 was committed. It's not obvious from the message but part of the changes were to automatically detach at rollback. If there's a more explicit section that I missed I'd be interested in seeing it though. -mike On Wed, Apr 21, 2010 at 6:07 AM, Adam Borkowski <[email protected]>wrote: > > Hi, > > 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 "persistentobjectdbi...@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(); > transaction.begin(); > > manager.persist(persistentObject); > > transaction.rollback(); > //assertFalse("Persistent object should be in New state after > rollback", manager.isDetached(notif)); > > EntityTransaction transaction2 = manager.getTransaction(); > transaction2.begin(); > > manager.persist(persistentObject); // this line throws exception > > transaction2.commit(); > > > > I'm using OpenJPA 1.2.2 and pessimistic LockManager. > > Best regards, > Adam > -- > View this message in context: > http://n2.nabble.com/Persist-on-the-same-object-fails-after-rollback-tp4936326p4936326.html > Sent from the OpenJPA Users mailing list archive at Nabble.com. >
