-->
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.  [ 4 posts ] 
Author Message
 Post subject: Transaction within a transaction
PostPosted: Wed Jul 07, 2004 10:17 am 
Newbie

Joined: Mon Jul 05, 2004 8:37 am
Posts: 15
Hello,

I'm trying to get a better understanding on how transactions work. I'm running within JBoss and I have to separate datasources set up to different databases. What happens when I open up a transaction within a transaction? For example:

// get session to first datasource
Session sessa = factorya.openSession();

// get session to second datasource
Session sessb = factoryb.openSession();


Transaction transa = sessa.begintransaction();
Transaction transb = sessb.begintransaction();

// Test is table in db 1
Test ta = new Test("testing);
sessa.save(ta);

// Stuff is table in db 2
Stuff sa = new Stuff("stuff");
sessb.save(sa);

transa.commit();
transb.commit();

I was having a problem where I forgot to close transb and transa did not commit. I was thinking they would be seperate transactions to different datasources and a should not lock if we forgot to close b.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 12:04 pm 
Newbie

Joined: Mon Jul 05, 2004 8:37 am
Posts: 15
I didn't mention I'm running in JBoss. From what I understand the begintransaction() method uses the current transaction if one is open. It seems like that is happening here.

Shouldn't there be a way to make two transacitons completely separate for two different datasources? My sessions come from two different session factories that I setup for each datasource.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 5:37 pm 
Newbie

Joined: Fri Sep 12, 2003 4:01 pm
Posts: 19
You say "forgot to close transb and transa did not commit". Could you be more precise here? By "forgot to close transb" do you mean that you didn't commit that transaction, that is, omitted the transb.commit() call? What precisely happened then, that is, what do you mean by "transa did not commit" ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 08, 2004 8:34 am 
Newbie

Joined: Mon Jul 05, 2004 8:37 am
Posts: 15
I did not commit transaction a. I had forgotten the call to trans.commit(). Transaction b was commited though but neither database was updated after the transb.commit(). I would have expected the database for transaction a to not update but I thought that transaction b would update since it was a different session factory for a second database.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.