openjpa-users mailing list archives

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

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 "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();
      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.

Mime
View raw message