-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: ASP.NET SessionState and persistent objects
PostPosted: Fri Jul 14, 2006 2:20 pm 
Beginner
Beginner

Joined: Fri Jul 14, 2006 1:51 pm
Posts: 27
It appears that bad things happen if you put a persistent object in session (not nhibernate session) and then try to access it later. I get "Could not initialize proxy - no Session." Before I start trying to dig into this too much I wanted to make sure it was or wasn't the way it should work. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 14, 2006 3:44 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
If you try to initialize any proxies and the session they were loaded in was closed, this is the error you get. Open a new session and reassociate the objects with it.


Top
 Profile  
 
 Post subject: reassociate method
PostPosted: Mon Jul 17, 2006 9:46 am 
Beginner
Beginner

Joined: Fri Jul 14, 2006 1:51 pm
Posts: 27
Can you post a code snippet demostrating that?


Top
 Profile  
 
 Post subject: Re: reassociate method
PostPosted: Wed Jul 19, 2006 8:50 am 
Beginner
Beginner

Joined: Fri Jul 14, 2006 1:51 pm
Posts: 27
anortham wrote:
Can you post a code snippet demostrating that?


Maybe a link to an example?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 11:38 am 
Beginner
Beginner

Joined: Wed Jul 19, 2006 8:24 am
Posts: 35
if I was needed to reattach an object to a session, most of the time I am using session.Lock(myObject, LockMode.None); with this method, the object is completely reattached to the session but tells NH not to reload any data. Since you are expecting that the data of an object may have changed, you will probably have to do a session.Lock(myObject, LockMode.Upgrade) or LockMode.Read. you are right that session.Update() will work too, but i'm not entirely sure how you might be using the feature and they are not the same.

session.Update() sends an UPDATE to the database. this assumes you have updated the object yourself outside of a session and you want to be sure those changes are persisted when reattaching to a new session.

session.Lock() can be configured to attach a detached object back to a new session and check the database (using the <version> property) to see if any updates to the object have happened while it has been detached.

my previous post wasn't meant to offend anyone; i run into the occasional bug or missing feature, but by-and-large i feel this library is the best thing .NET has going for it.


Top
 Profile  
 
 Post subject: One more question on this subject
PostPosted: Fri Jul 21, 2006 6:32 pm 
Beginner
Beginner

Joined: Fri Jul 14, 2006 1:51 pm
Posts: 27
I have a page in asp.net for testing purposes. I have one button that fires an event to load an appuser object from nhibernate and store it in the asp.net session. That's in one httprequest. Then I click another button that sets the value of a text box equal to the fax number of that appuser object.

The problem is that it will throw a lazyinitialization exception when reading the fax number. Why would I even get an nhibernate exception when I'm only trying to read a non lazily loaded property of an object I just stored in session?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.