ObjectDB ObjectDB

Rollback after commit fail

#1

Hi,

I have question regarding transaction management in ObjectDB.

Consider following scenario:

Thread 1:

try{

    EntityManager em = emf.createEntityManager();

    em.getTransaction.begin()

    persist object1

    em.getTransaction().commit();

} catch(...){

    em.getTransaction().rollback();

}

 

Thread 2:

try{

    EntityManager em = emf.createEntityManager();

    em.getTransaction.begin()

    persist object2

    persist object1

    em.getTransaction().commit();

} catch(...){

    em.getTransaction().rollback();

}

 

Parallel running threads caused that second thread commit will fail (primary key reuse exception), the exception is caught,

but rollback fails with:

javax.persistence.TransactionRequiredException
Attempt to rollback a transaction when no transaction is active (error 611)

So the transaction seems to be already closed.

When looking into db, the transaction seems to be rollback, so when commit fails, we don't have to call rollback explicitly?

Thanks

Marta

 

edit
delete
#2

The transaction is rolled back automatically if the exception is thrown during commit.

But consider using the following code:

} catch(...){
    if (em.getTransaction().isActive()) {
        em.getTransaction().rollback();
    }
}

This should cover both exception in commit or before commit. It would also help if ObjectDB behavior regarding automatic rollback would be changed in future versions.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.