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: NHibernate 2.0 and Transactions
PostPosted: Fri Nov 07, 2008 11:39 am 
Newbie

Joined: Wed Aug 20, 2008 4:20 am
Posts: 5
Hi,

I noticed that the NHibernate 2.0 breaking changes list states that all database operations have to be within a transaction.

I am using some code that previously used NHibernate 1.2. There are queries etc. that are not wrapped within a transaction, yet they still seem to work.

The application uses ASP .NET and a custom HttpModule for referencing the session. I would appreciate some advice about what modifications are needed for this existing code.

Cheers,

James


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2008 11:49 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
In Hibernate 2.0 you cannot take advantage of "contextual sessions" on a managed environment, so your options for ensuring that every DB operation is wrapped in a transaction are:

-writing wrapping transaction code manually each time

-creating a base Data Access class, which all your DAO classes will extend, and which has basic insert(bean) delete(id) update(bean) executeSelect(SQL) methods, and inside each of those methods one session is obtained with Threadlocal and a transaction is created/begun/commited/trycached.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2008 5:18 am 
Newbie

Joined: Wed Aug 20, 2008 4:20 am
Posts: 5
Hi,

Thanks for the reply Gonzalo. I was wondering what the possible consequences of executing queries outside a transaction might be? The existing code still seems to work but I have not had time to fully test it. There is quite a lot of code that will need to be changed.

BTW, as I am using ASP .NET the NHibernate session is created on each HTTP request so I didn't need to manually declare it as threadlocal.

Cheers,

James


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.