-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Different Persistence Context but same Transaction Java SE
PostPosted: Mon Dec 08, 2008 3:20 pm 
Newbie

Joined: Tue Mar 04, 2008 10:37 am
Posts: 6
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.