-->
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.  [ 8 posts ] 
Author Message
 Post subject: ITransaction Use Best Practice
PostPosted: Fri Sep 16, 2005 5:56 pm 
Beginner
Beginner

Joined: Fri May 13, 2005 11:48 am
Posts: 32
Code:
using(ITransaction tr = sess.BegineTransaction){
   ...
   tr.Commit();
}


or

Code:
ITransaction tr = sess.BeginTransaction();
try{
   ...
   tr.Commit();
}
catch
{
   tr.Rollback();
}
finally
{
    tr.Dispose();
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 17, 2005 10:34 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I usually use the first style in NHibernate tests, the second is also certainly possible. ITransaction.Dispose actually doesn't call Rollback explicitly, but since it calls Dispose on the ADO.NET IDbTransaction it wraps, the transaction should be rolled back anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 17, 2005 12:00 pm 
Beginner
Beginner

Joined: Fri May 13, 2005 11:48 am
Posts: 32
sergey wrote:
in NHibernate tests,


Do you mean in THE NHibernate test or in tests of my app that use NHIbernate?

Is the fisrt style going to work in a production environment?

I am just curious. Thanks for the input. Is the a Best Practice area?

dru


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 18, 2005 9:07 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I meant the unit tests that are part of NHibernate source, used to test NHibernate itself. Yes, the first style should work in a production environment (or at least I can't see any reason why it should not work, and I never heard that it didn't). As for Best Practice area, I don't know of any, and don't see many posts related to best practices, but we can of course create a forum for them if people want it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 7:07 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Is it best practice to dispose of a transaction after you are done with it? I haven't seen that mentioned anywhere.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 3:16 pm 
Beginner
Beginner

Joined: Fri May 13, 2005 11:48 am
Posts: 32
I would because otherwise you are going to have a transaction waiting for the session to close. So if you are done with the transaction, but not the session i think that it would indeed be a best practice to dispose of the transaction.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 4:41 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Actually, Commit and Rollback call Dispose in the current implementation.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 12:17 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Great. Thanks Sergey. thats what I thought should happen. So there is no need to call dispose explicitly.


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