pjaffe
12-26-2006, 04:32 PM
Am I correct that Spring's support for nHibernate requires disabling the lazy initialization of nHibernate persistent objects?
I first tried using nHibernate 1.2 Beta with Spring 1.1 Preview 3 and got a System.InvalidOperationException:"Unable to make a reference to a transient module from a non-transient module" when using the Spring.Web bidirectional databinding.
When I dug into the problem, I found that the Spring.Web databinding attempts to generate runtime IL in Spring.Util.DynamicReflection.BaseDynamicMember.Se tupTargetInstance(...) that invokes property accessors on a nHibernate generated proxy object. If I explicitly set default-lazy="false" in the nHibernate mapping, the web tier databinding works since the target object is now the compile time defined domain object rather than a runtime generated nHibernate proxy.
It really seems like it would be nice to take advantage of nHibernate's default behavior of lazy initialization, particularly since I have a complex domain model which would only be partially exercised in any particular web request, and loading all dependent domain objects would be an unnecessary performance and memory hit.
I have started looking at the Spring nHibernate module and the HibernateTemplate class to see if it handles things any differently, but haven't really gotten any test cases up yet since I'm a bit confused by the nightly build whose source code contains the Spring.Data.NHibernate.Generic namespace but seems to have an unresolvable reference to the rest of the Spring.Data.NHibernate namespace which maybe depends on the previous NHibernate module...
My bottom line question is: Does Spring.NET's Web databinding support NHibernate's lazy initialization, and if so, what I am doing wrong?
Also, let me know if I should have posted this in the Web forum. I thought this question was so specifically targeted to NHibernate, that this was the better place.
Thanks,
Pete
I first tried using nHibernate 1.2 Beta with Spring 1.1 Preview 3 and got a System.InvalidOperationException:"Unable to make a reference to a transient module from a non-transient module" when using the Spring.Web bidirectional databinding.
When I dug into the problem, I found that the Spring.Web databinding attempts to generate runtime IL in Spring.Util.DynamicReflection.BaseDynamicMember.Se tupTargetInstance(...) that invokes property accessors on a nHibernate generated proxy object. If I explicitly set default-lazy="false" in the nHibernate mapping, the web tier databinding works since the target object is now the compile time defined domain object rather than a runtime generated nHibernate proxy.
It really seems like it would be nice to take advantage of nHibernate's default behavior of lazy initialization, particularly since I have a complex domain model which would only be partially exercised in any particular web request, and loading all dependent domain objects would be an unnecessary performance and memory hit.
I have started looking at the Spring nHibernate module and the HibernateTemplate class to see if it handles things any differently, but haven't really gotten any test cases up yet since I'm a bit confused by the nightly build whose source code contains the Spring.Data.NHibernate.Generic namespace but seems to have an unresolvable reference to the rest of the Spring.Data.NHibernate namespace which maybe depends on the previous NHibernate module...
My bottom line question is: Does Spring.NET's Web databinding support NHibernate's lazy initialization, and if so, what I am doing wrong?
Also, let me know if I should have posted this in the Web forum. I thought this question was so specifically targeted to NHibernate, that this was the better place.
Thanks,
Pete