-->
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: Uncommitted transaction policy
PostPosted: Mon Jan 21, 2008 3:44 am 
Beginner
Beginner

Joined: Thu Apr 27, 2006 5:49 am
Posts: 31
Recently I've been checking my project code and find out that there are places where exception handling is done wrong. In some places I can see the following code:

Code:
    ITransaction transaction = session.BeginTransaction();

    try
    {
        if (objectToPersist == null)
        {
            throw new ArgumentNullException();
        }
        transaction.Commit();
    }
    catch (NHibernateException e)
    {
        transaction.Rollback();
    }


It is not exactly like that, because beginning and ending transaction are actually done in the web layer, but in general it looks like that.

So, my warning is, what will happen if the method throws ArgumentNullException? Transaction is already started, but won't be rolled back, since expected exception type is NHibernateException. Will transaction still try to flush data? Will unclosed transaction cause any other side effects? Is there are way to control the behaviour of uncommitted transactions? Of course, I want all uncommitted transactions to be rolled back.

P.S. I know that this code is generally wrong, but it will take time to fix it and I want to be sure that it is still okay to have code like that.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 21, 2008 5:23 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Unfortunately I believe this is database dependent. For example, Oracle can be configured to autocommit rather than autorollback however if you're using MS SQL Server it will autorollback by default.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 21, 2008 6:06 am 
Beginner
Beginner

Joined: Thu Apr 27, 2006 5:49 am
Posts: 31
merge_s.rottem wrote:
Unfortunately I believe this is database dependent. For example, Oracle can be configured to autocommit rather than autorollback however if you're using MS SQL Server it will autorollback by default.


Great, just what I needed to know. I am using MS SQL Server 2005. :)


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.