openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Malte <malte.neum...@googlemail.com>
Subject Problem with EntityExistsException
Date Mon, 24 Apr 2017 15:55:11 GMT
Hello all!

In a special situation, I'll get a wrong EntityExistsException.

I've extract the problem to a simple project (attached).

I do this:
   try {
     entManager.persist(data);
     entManager.flush();
     entManager.detach(data);

     doOtherDBCallsWithError();

     entManager.getTransaction().commit();
   } catch (Exception e) {
      entManager.getTransaction().rollback();

      entManager.getTransaction().begin();
      entManager.persist(data);
      entManager.getTransaction().commit();
   }

If doOtherDBCallsWithError throws an Exception, it is not possible to
persist the object in the catch-block. The second persists throws
"org.apache.openjpa.persistence.EntityExistsException: Attempt to persist
detached object "de.test.model.Test-1".  If this is a new instance, make
sure any version and/or auto-generated primary key fields are null/default
when persisting." If I use merge instead, the object will also not persist.
If I remove the detach, everything works.

Is this a bug or is the call order persist-flush-detach-commit against the
specification?

Best regards,
Malte

Mime
View raw message