0
@Singelton
class A {


@Resource 
private TrsnactionSynchronizationRegistry tsr;

    @TransactionAttribute(TransactionAttributeType.Required)
    method () {

     // here tsr.getTransactionStatus() is 0 means active
     EntityClass entity = new EnityClass(); 
     em.persist(entity);// Duplicate Key exception
     em.flush();
     // here tsr.getTransactionStatus() is 1 means markedForRollback;



    }

In ejb singletion bean using container managed transaction and hibernate as per the code above. After running the em.persist(entity) because of Duplicate key Exception the transaction was marked for rollback. But i want to keep the transaction active , how can i avoid it or change the status of the transaction to active.

pvjhs
  • 549
  • 1
  • 9
  • 24
  • And then how are you going to ensure that the duplicate key issue is actually rollbacked? mark you, the transaction is only marked for rollback, it is not yet rolled back, and that happens after the method returns. – maress Jul 02 '18 at 08:13
  • i will delete already existing enitity with same key in database. Anyways , if it is marked for delete can we still have a chance to continue things in transaction . I am unable to think that part can u give me an example. – pvjhs Jul 03 '18 at 03:31

0 Answers0