We had a similar problem where we wanted to store our objects in Session and Application variables and ViewState. We also had scenarios where objects had to be sent across application boundaries via remoting etc.
We found that what worked for us is to implement GetClone() for all our domain objects. If a domain object had references to other domain objects, its GetClone() would in turn call GetClone() for all the referred domain objects. Though you need to ensure that there are no circular references. //when Saving Session["SomeVar"] = object.GetClone() //When retrieving object = (Cast)Session["SomeVar"]; session.Lock(object); //Attach back to session Also it helps that Nhibernate Session methods like Save() automatically attach a detached object back to session. all said, I am not sure if this is the best way to go, and would sure love to hear some better ideas from the community. On Mar 4, 1:58 am, hankor <[email protected]> wrote: > Hi all, > > I currently need to refactor a big web application using an ORM > framework. I would really like to use nhibernate for this & have done > several tests that show that things would work out well. I have one > problem left though that is giving me headaches: > > I want to use one session per request. I will have to use lazy-loading > a lot. > The application does at numerous places store things in the asp.net > session or the asp.net cache. > > When the application now loads a lazy property for an object that has > been loaded from there, nhibernate throws - no suprise - a > lazyinitializationexception. > I know I have to reattach the item to the session first. > > BUT, due to the sheer size of the application I can't modify/review > all places where that happens (which I know in an ideal world I would > have time to do). > > So my question is: Is there any way to intercept the lazy-loading and > check for an existing session previously and reattach if there is > none? > For lazily loaded properties I think I could modify the intercept > method of the generated proxy. > What would I do for lazily loaded collections (where > abstractpersistentcollection throws the exception) though? > > The only thing I could come up with so far is to use a AOP framework > like postsharp to intercept the calls, but this would be kind of a > pain too because this would have to be integrated into the general > build process. > > Any suggestions for easier ways to solve this? > > Any help is much appreciated & sorry in case this already is answered > somewhere that I didn't find. -- 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.
