-->
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.  [ 3 posts ] 
Author Message
 Post subject: Let see if anyone can answer this one!
PostPosted: Sun Jul 18, 2004 3:19 am 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
Hello Guys,
Standard Transaction code is usually like this rite(as in the docs)?

Session sess = factory.openSession();
Transaction tx;
try {
tx = sess.beginTransaction();
//do some work
...
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
sess.close();
}

ok now, my question is : what if in the "//do some work" block, i create a new object that i want to be persisted when the transaction commits, but however, according to what i experienced, tx.commit only commits already persistent objects that have been modified in some way in the "//do some work" block. tx.commit, however, does not persist the new object that i have created. for that to happen, i will have to call session.save(). The problem is what if i have already called session.save on that new object and some where down the line of the transaction, an error occurs and whatever changes that i have made to the persistent object is rollback by tx.rollback() BUT my newly created object which is supposed to be part of the transaction isnt rollbacked cos it is already saved to the database!! what kind of transaction is this?! or am i missing out on something that i dont know??? can some guru please enlighten me ? a transaction has either be successful or not successful and all changes are made persistent or all rollbacked, but in this case, it seems that my transaction is a half baked one, allowing my newly created object to stay persistent in the database even when a tx is rollbacked?! what gives???





Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 18, 2004 3:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate does not implement object-level rollback. Most applications do not need this, and it is a performance drag. At some stage we will provide it as non-default behavior.

So the tx rollback is a pure database-level thing.


Top
 Profile  
 
 Post subject: Re: Let see if anyone can answer this one!
PostPosted: Sun Jul 18, 2004 10:44 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
Just work around this constraint. Maybe create the object with a delete date, then update the delete date to null in the transaction... if the transaction fails then the object will be created and deleted so it wont matter. There are probably other creative solutions to this as well. Chris


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