Domanda

Do you know how I can get XAResource that is automaticaly enlist to my transaction when I use my entity manager ?

I use Bitronix, JPA, hibernate, my code works fine, but I don't want to rollback all my XAResources if one specific failed. I just want to delist it from the current transaction and others will be commited.

But for delist it of the current transaction, I need the object XaResource and I don't know how i get it with JPA/Bitronix. example of code :

transactionManager.begin();
try {
    (...)
    EntityManager em = emf.createEntityManager();
    (...)
    em.close();
} catch (Exception e) {
    // old version - rollback every XaResource in the current transaction
    //transactionManager.rollback();
    //new version wanted - rollbackonly this XaResource    
    transactionManager.getTransaction().delistResource(XaResource ...);
    throw e;
}
transactionManager.commit();

Thanks for your help.

È stato utile?

Soluzione

The A(tomicity) property of ACID doesn't allow such scenario. The transaction can only be successful if all data sources were able to commit.

I think the Command Pattern can help you with your problem. Let's say you want to update two data sources, and if one fails you still have control whether to undo the already executed commands.

If you never want to undo, then you don't need XA transactions. You just have to use Resource Local transactions, and if one data source fails, the rest could proceed.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top