-->
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: Transaction Not Rolling Back
PostPosted: Wed Aug 09, 2006 7:52 pm 
Newbie

Joined: Thu Aug 03, 2006 6:54 pm
Posts: 16
Hello Hibernate Users,

I am trying to execute a transaction using Hibernate that updates two databases. Suppose that inside my UserTransaction I update my first database, then (in the same UserTransaction) while I update my second database the entry in the first database gets deleted. Ideally the second database should not be updated and the whole UserTransaction should roll back. However in my case the second database is still being updated i.e. the transaction is not rolling back.

My test code is shown below (Where utx is an instance of a UserTransaction, ctmr is an instance of my Customer class, fts is an instance of my FinancialTransaction class, sf and sf2 are instances of my Session Factories - one for each database):

Note: the purpose of putting the thread to sleep is so that I can delete the entry in the first database from outside the UserTransaction.

Code:
utx.begin();
session1 = sf.openSession();
session2 = sf2.openSession();
session1.beginTransaction();
session2.beginTransaction();
                  
session1.save(ctmr);
session1.flush();

t.beep();
try{
   Thread.sleep(10000);
}catch(InterruptedException e){}
t.beep();
                     
session2.save(fts);
session2.flush();
session2.getTransaction().commit();
session1.getTransaction().commit();
utx.commit();


I think what is happening is that on its own Hibernate creates another session object while updating the second database. Hence the UserTransaction does not roll back

If anyone knows of a way around this that would be greatly appreciated. At the moment I only use the UserTranscation interface of JTA. I was wondering whether I need to make use of the XAResource or the TransactionManager interfaces? The other idea I had was to make changes to JTA itself.

If anyone can provide any help on the matter it would be greatly appreciated.

Outlaw


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.