-->
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: Multiple rollbacks and commits in a single transaction
PostPosted: Thu Nov 11, 2004 4:21 am 
Newbie

Joined: Thu Oct 21, 2004 8:13 am
Posts: 8
Hello,
i am having problems using a single transaction and having multuple commits and rollbacks with the rollbacks rolling back previous commits. I have even set the flush mode to commit but still the rollbacks rollback my previous commits. ok this is what i am trying to do:

get a list of Xobjects with hql
go thru each one of them in a loop
{

try{
create new Yobject
sess.save(Yobject)
tx.commit();
}catch(Exception ex)
{
tx.rollback();
}


try{
create new Zobject
sess.save(Zobject);

if(true)
throw new Exception("test")

tx.commit()
}catch(Exception ex)
{

tx.rollback();
}

}

this is just the summary of the code but as you can see, the second try catch block, i purposely throw an exception in order for the tx to rollback but i realize that the rollback also rollbacked my previous commit in a way that Yobject was not saved into the database. what i understand is that commit synchronizes the state with the database and i saw the sql to insert Yobject being displayed on my console. i have also tried to set flush mode to commit on session object but the Zobject rollback still undid the commit on Yobject. am i doing anything wrong here?

it is important for me to go through this loop and have a series of commits and rollbacks for a failover mechnism i am working on but it seems that the behaviour described above is not acceptable for my failover mechanism. should i be creating new transactions for each Yobject and Zobject so that when Zobject rollback is called, it will not affect the transaction of Yobject?

if that is the case, wouldnt that sound expensive to create 2 x transactions for each loop, well of course using the same session

Can anyone please shed some light ?

Thanks


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.