Hi,
I am asking myself if it is possible to have one transaction for more than one EntityManager with different persistence contexts.
Technicl data:
Hibernate 3.3.1.GA:
Oracle 10g:
Java SE
Transaction Type: RESOURCE_LOCAL
JPA( with a few Hibernate specific methods and annotations)
A short example will demonstrate what I mean:
Code:
EntityManagerFactory entityManagerFactory =
Persistence.createEntityManagerFactory("MasterResource");
EntityManager em1 = entityManagerFactory.createEntityManager();
EntityManager em2 = entityManagerFactory.createEntityManager();
TestEntity te = new TestEntity();
em1.getTransaction().begin();
em2.persist(te);
em1.getTransaction().commit();
The problem with this example is that em2 has its own transaction and "te" is not fushed to the database until I call:
Code:
em2.getTransaction().begin();
em2.getTransaction().commit();
So basically I have different EntityManager with different persistence contexts and different transactions. Now I want all these EntityManager to share same transaction.
Is there a way to do this with Hibernate?
Thanks for any help
Cheers Tim