-->
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: General question about transactions commit and rollback.
PostPosted: Sun May 16, 2010 1:53 pm 
Beginner
Beginner

Joined: Fri Dec 10, 2004 11:46 pm
Posts: 37
Hi I just have a question about commit and rollback. I'm sure this is probably very database vendor dependent, but I was hopping maybe some of you have an insight...

What happens if....

try
{
begin transaction

// Do 1
// Do 2
// Do 3 <-- DB network disconnected at this point of time.
// Do 4
commit transaction <-- Fails because DB is disconnected
}
catch
{
rollback <-- Fails because DB is disconnected
}

Does hibernate send everything to the DB at commit? (I assume that is when it flushes be default unless you otherwise say so to Hibernate right?)
So if the above is true and commit fails, rollback will obviously fail also cause the DB is still disconnected. But what happens to the begin transaction in the database?


Top
 Profile  
 
 Post subject: Re: General question about transactions commit and rollback.
PostPosted: Sun May 16, 2010 4:53 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
Does hibernate send everything to the DB at commit? (I assume that is when it flushes be default unless you otherwise say so to Hibernate right?)


Flushing can happen at other times also (eg. before executing a query). You can change the default by specifying a different FlushMode. See http://docs.jboss.org/hibernate/stable/ ... e-flushing for more information.

Quote:
So if the above is true and commit fails, rollback will obviously fail also cause the DB is still disconnected. But what happens to the begin transaction in the database?


The database should of course detect this and rollback anything that has already been sent in that transaction. This assumes that you are using a database that does support transactions. One exception is MySQL with the MyISAM engine.


Top
 Profile  
 
 Post subject: Re: General question about transactions commit and rollback.
PostPosted: Sun May 16, 2010 11:31 pm 
Beginner
Beginner

Joined: Fri Dec 10, 2004 11:46 pm
Posts: 37
Thanks I'll look at the flush modes.

I'm using MSSQL 2005

So if I get it the DB will try to rollback even if it doesn't explicitly get a rollback from the application?


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.