-->
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.  [ 6 posts ] 
Author Message
 Post subject: One transaction cover two connections databases different
PostPosted: Sun Feb 22, 2009 2:11 pm 
Newbie

Joined: Sun Sep 07, 2008 12:39 pm
Posts: 3
Good morning.
I have two databases.
First delete records of a table of the first database and after, these records deleted, i want insert it in a table of the second database.
I need these two operations are handled by a single transaction, because if a error occurs, i want to do a rollback over those two databases.
At first, i had a session and a transaction for the first database and another session and transaction for the second database. Then, i opened the two transactions simultaneously, but the operations worked bad. Maybe you can not open two transactions simultaneously:

Code:
Session session1 = HibernateUtil.getSession1();
Transaction tx1 = session1.beginTransaction();
Session session2 = HibernateUtil.getSession2();
Transaction tx2 = session2.beginTransaction();
.....
.....
operations....
.....
.....


Can anyone help me?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 22, 2009 3:53 pm 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
Have you considered using JTA for managing the transactions?

--
Stephen Souness


Top
 Profile  
 
 Post subject: One transaction cover two connections databases different
PostPosted: Sun Feb 22, 2009 4:16 pm 
Newbie

Joined: Sun Sep 07, 2008 12:39 pm
Posts: 3
Can not hibernate handle it alone?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2009 2:23 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
I did a google on this and what I could find is that Hibernate's transaction API is for single DB. But if you want cross-DB transaction you can plug-in JTA to hibernate.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2009 9:43 am 
Newbie

Joined: Sun Sep 07, 2008 12:39 pm
Posts: 3
Is there something that explains how to do that?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2009 9:49 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
May be this will help you in making hibernate to use JTA transactions instead of its native transaction api:
http://www.hibernate.org/42.html

If you search the web u ll find tutorials on JTA for JTA how to.

_________________
Regards,
Litty Preeth


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

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.