Strange FHibernate behaviour
Good day,
here is some behavior i discovered in FH...
I have an object A, which has a collections of objects of B and C as public virtual IList.
All of them mapped to DB. At program start i read object A from DB and may loop through collections B and C as well.
I pass object A for the future work with. Then i close session.
Once i try to read A and its collection in some time, i get exceptions reading collections of B and C.
Exception:
Initializing[A#1]-failed to lazily initialize a collection of role:B, no session or session was closed
Silly thing here - once i loop through this collection after A object read in Debug time (just in Visual Studio debugger), object can be read normally later. (or the same they successfully accessed one i read these collections Count for example or anything other field).
Any workaround this issue?
2 Posted by Arkady on 30 Jun, 2010 02:04 PM
Ok.
It seems like
Not.LazyLoad()
helps... But what is it LazyLoad then? Does it mean i have to stay connected to DB for the whole time program launched?? Seem to me some kind of useless mode, or is there any other suggestion - why this LazyLoad mode exists?
Support Staff 3 Posted by Paul Batum on 07 Jul, 2010 11:57 AM
Lazy loading is a popular option that most people use. Its not a typical
usage pattern to retrieve an object from the session and then close the
session and continue to work on it, as the session does not maintain an
active connection to the database.
I suggest you read the nhibernate documentation:
http://www.nhforge.org/doc/nh/en/index.html#collections-lazy
If you have more questions, I suggest you ask on the nhibernate
users<http://groups.google.com/group/nhusers/> mailing
list as they handle general NH related queries.