You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Adam Borkowski (JIRA)" <ji...@apache.org> on 2010/04/25 18:37:49 UTC

[jira] Created: (OPENJPA-1640) Rollback in extended persistence context doesn't move persistent object to new/transient state

Rollback in extended persistence context doesn't move persistent object to new/transient state
----------------------------------------------------------------------------------------------

                 Key: OPENJPA-1640
                 URL: https://issues.apache.org/jira/browse/OPENJPA-1640
             Project: OpenJPA
          Issue Type: Bug
    Affects Versions: 1.2.2
            Reporter: Adam Borkowski


According to the diagram which describes lifecycle of the entity on page 71 of the 1.2.2 manual, 
one can see that from "managed" state entity can go back to "New/Transient" by rollback*, where
* = Extended persistence context 

It seems that it's not the case. I'm using extended persistence context in a standalone application.
When trying to persist object after it was persisted and transaction was rolled back, I get following 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."

It looks like after rollback entity goes to the "detached" state.

This behavior prevents from performing simple retry of transaction operating on the same persistent 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();



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.