Lazy-loading fails when session got disconnected?

There is no efficient way to do that. The idea is that you keep the session open until your done with the session. There should be one session per unit of work.(a session is kind of unit of work actually).

There is no efficient way to do that. The idea is that you keep the session open until your done with the session. There should be one session per unit of work.(a session is kind of unit of work actually).

Fetching everything your need in one query is more efficient than fetching everything you need in multiple queries, so I don't agree with your last statement. Lazy loading is useful for lazy programmers (like me) but is never more efficient than eager loading. Lazy loading can save you some programming time, but you still have to watch out for to many queries being executed (select N+1).

About your query count issue... You can mitigate this effect by using Batch loading in your persistence unit (so when you access a "child" of an instance of Parent, Nbernate gets up to ``BatchSize "child"ren for all "currently known" Parents. I let your to the documentation for more about this. Also, Lazy Loading is more efficient in average than Eager when "most of time" you don't use the "lazy children" of a Parent entity.It's highly use-case dependent ultimately.

– Romain Feb 17 '10 at 20:49 @Romain Muller: 1. ) Batching can be used for several performance optimations, from which select n+1 is on of them. Another one is paging and I use it for more things, but batching does not prevent every select n+1, it will just convert "select n+1" into "select n/b + 1" most times.

2. ) Not loading is a different thing than lazy and eager loading. I don't mean to use eager in the mapping, I mean to use eager in the query.

– Paco Feb 17 '10 at 21:31 @Paco, I'm not really into the discussion of whether or not to Lazy Load... I've already decided to go for it. My data-access layer gives me an object, which in 7 out of the 10 times, I just use as is.In 3 out of the 10 times, it needs to post-fetch some lazy properties. I do accept the performance bottleneck and I'm aware of N+1.

This is the idea of lazy-loading in my sense (functionally). I guess what I'm asking here is just the technical implementation. – taoufik Feb 18 '10 at 10:03 @Paco, Futher... No, I don't want to keep my connection open, because I believe my connections are expensive to keep open only "in case of" and the session should take care of it.

And I don't agree with you regarding "session == UoW", a session doesn't have to be short-running UoW, you can also have a long-running session, which you connect and disconnect whenever you want to perform an action. See for example, the samples in NH where they keep the session in a ASP. NET session.

– taoufik Feb 18 '10 at 10:08 1 Keeping a session in an asp.Net session can give you memory problems, because of the large amount of memory needed by the first level cache. Connections are managed by the session already, so there is no need to open/close connections manually. Your connectionpool won't be exhausted by keeping sessions open."session == UoW" is not invented by me, but by the creators of N – Paco Feb 18 '10 at 12:38.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions