In legacy code I solving problem with nested transactions. (Spring, CDI, etc cannot be used only pure JPA(EclipseLink))
em.getTransaction().begin();
em.persist(client);
em2.getTransaction().begin();
em2.persist(client1); //saved into DB
em2.getTransaction().commit();
em.getTransaction().rollback();
public void method(){
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
em.persist(client);
nestedTransactionMethod();
em.getTransaction().rollback();
}
public void nestedTransactionMethod(){
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
em.persist(client);
em.getTransaction().commit();
}
the problem is when I call inside method where is opened transaction another method with self transaction than it not behave atomic. Is there any solution how to achieve this without giving open entity manager as parameter?
Aucun commentaire:
Enregistrer un commentaire