-->
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.  [ 5 posts ] 
Author Message
 Post subject: how to roll back ?
PostPosted: Mon Oct 01, 2007 3:13 am 
Beginner
Beginner

Joined: Mon Jul 30, 2007 4:58 pm
Posts: 21
What happens if I rollback a transaction after I flush ? Does it roll back ?

My Problem is that I have a batch update process through my web app. And during that process I have to do session.flush() and session.clear() frequently. However the server sometimes crashes.

And I want to ensure that if server crashes the entire batch process is rolled back. How can I do it ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 6:14 am 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
Hi emperon,

In my experience, calling session.Flush() will do a Commit() for you. So I would answer, no you can't rollback a transaction after flushing.

[ed: NB I was absolutely wrong, it doesn't ;-0]


Last edited by PandaWood on Sat Jul 12, 2008 10:38 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 6:53 am 
Beginner
Beginner

Joined: Mon Jul 30, 2007 4:58 pm
Posts: 21
I think you are wrong. I am digging the issue. And I see flushing the session just runs the queries to be run on the database. But they still reside within the transaction. So YOU CAN ROLL BACK the transaction even if it is flushed.

Because basically flushing is the same as running the insert query (for e.g) by standard ado.net. And if you run an insert query within ado.net you can still roll it back safely. But I cannot speak for the impact of a transaction that has thousands of individual inserts.

Finally you know occasionally hibernate flushes the session by itself even if you do not flush it explicitly. If what you said were true , transactions would be completely pointless to use.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 8:52 am 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
I think you're right. Although there's certainly some confused terminology in regards to this. For example, NHibernate in Action, says things like this:

We’ve noted that the call to Commit() synchronizes the ISession state with the database. This is called flushing, a process you automatically trigger when you use the NHibernate ITransaction API.

Flushing the ISession state to the database at the end of a database transaction is required in order to make the changes durable and is the common case

If flush() doesn't commit (I admit, if it did it would seem pointless), I still wish they wouldn't word things like that. It looks like they have a process called 'flushing' but which is not necessarily done by calling 'flush()'.

Still, I've learnt more by answering questions wrongly in the last few days, than I have in weeks of reading books. So thanks for putting up with me.


Last edited by PandaWood on Sat Jul 12, 2008 10:39 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 9:34 am 
Beginner
Beginner

Joined: Mon Jul 30, 2007 4:58 pm
Posts: 21
hehe no problem pal I am learning too. Btw why don't you come to IRC if you are so willing to discuss on nhibernate. irc.freenode.net #nhibernate. It's a ghost channel but I sometimes ask my hopeless questions there.


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