Ramon,

 

"one uow = one session = one transaction" I can agree with. But "Http
request = one uow" can be a real issue, especially when acting as a "front
end" for a highly distributed environment. Each "Back end" element often
needs to be a uow, with all of them (possibly some succeeding, some failing)
in one HTTP round trip.

 

DAvid

 

 

From: [email protected] [mailto:[email protected]] On Behalf
Of Ramon Smits
Sent: Sunday, April 29, 2012 3:04 PM
To: [email protected]
Subject: Re: [nhusers] Transaction management

 

Currensessioncontext is only a method to retrieve the nhibernate session for
the current uow. There are other ways to manage a session reference for
example via injection.

 

The problem is more related to transaction management. When and how to
manage these especially in composited pages that contain several independent
controls, sections or whatever name it has. You could consider that such a
request has several uow's. 

 

I would say that a uow resembles one and exactly one transaction. AFAIK it
is good practice to not re-use a nhibernate session once a transaction is
completed. It does not matter is the transaction either was committed or
rolled back.

 

However, there is only one exception and that is when you have multiple
read-only uow's that do not explicitly use a transaction. Pre-loading the
1st level cache would improve performance when these uow would share the
same entities thus resulting in less db roundtrips. Still, it is advised to
also perform your readonly queries in one transaction.

 

It is for these reasons that I try to always try to have:

 

Http request = one uow = one session = one transaction

 

 

Ramon


On Sunday, April 29, 2012, Alex Norcliffe wrote:

That's not what I meant. Many sources recommend using the "web" NHibernate
session context (NHibernate.Context.CurrentSessionContext) for an ASP.NET
application, which ties a session to an HTTP request lifecycle (I'm not
suggesting or condoning sharing NH sessions across requests via ASP.NET
sessions)

 

My question was - are you suggesting that an NH session is intrinsically a
single unit of work? Because if you use the above context (wherein the
NHibernate.Context.CurrentSessionContext will always return the same NH
session for a single HTTP request) would imply otherwise, either that or you
expect a single HTTP request to conduct only one unit of work

 




Alex Norcliffe

Lead Architect, Umbraco 5
ASPInsider
Microsoft Regional Director

 <http://twitter.com/alex_norcliffe> @alex_norcliffe on Twitter, blogging at
<http://boxbinary.com/> boxbinary.com

 





On 29 April 2012 20:25, Ramon Smits <[email protected]
<javascript:_e(%7b%7d,%20'cvml',%20'[email protected]');> > wrote:

 

On Sun, Apr 29, 2012 at 8:47 PM, Alex Norcliffe
<[email protected]
<javascript:_e(%7b%7d,%20'cvml',%20'[email protected]');> >
wrote:

@Ramon - Are you suggesting that the OP should have one session per unit of
work? Do you have any documentation to support this recommendation? It goes
contrary to the session context one might use in a web environment, for
example.

 

I don't understand your question. An asp.net session is something totally
different then an nhibernate session. An asp.net session makes it possible
to share certain state for a specific browser session at the server between
requests.

 

An nhibernate session should definitely not be stored in an asp.net session!
Well, maybe there is the ability to disconnect a session at the end of a
request and reconnect it at the start of a request but this would be bad
practise I guess.

 

NHibernate sessions should have a short life span in web applications.

 

Ramon

-- 
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
<javascript:_e(%7b%7d,%20'cvml',%20'[email protected]');> .
To unsubscribe from this group, send email to
[email protected]
<javascript:_e(%7b%7d,%20'cvml',%20'nhusers%[email protected]')
;> .
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.

 

-- 
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
<javascript:_e(%7b%7d,%20'cvml',%20'[email protected]');> .
To unsubscribe from this group, send email to
[email protected]
<javascript:_e(%7b%7d,%20'cvml',%20'nhusers%[email protected]')
;> .
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.



-- 

Ramon

 

-- 
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to