-->
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.  [ 5 posts ] 
Author Message
 Post subject: HttpSessionState and persistent objects
PostPosted: Thu Sep 20, 2007 10:54 am 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
I have searched the forum and found some posts favoring using the second-level cache instead of session state when using nHibernate in a web context. But i would like to see some arguments for this approach, as i can not see why it should be better?

The scenario: A typical shoppingbasket needed to be stored in session state for users browsing the product-catalog on a webpage. We have introduced a class called BasketItem having properties NumberOfItems and Item which references the actual Product bought. Price and discount information on the products is used on everypage to calculate the total price and a few other things so i like having it in session, and our products don't change often.

Here comes the catch. A product has a lazyloaded collection which is only needed when showing the contents of the shoppingbasket, but the session is now lost. So i have to reattach the Product objects from HttpSessionState to my current ISession using ISession.Lock(myProduct, LockMode.None).

So my question, is this ISession.Lock call expensive? (it does not look that way looking at logfiles and the actual code) And what would the arguments be in this scenario against this approach and for second-level cache?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 1:35 pm 
Beginner
Beginner

Joined: Wed Jul 19, 2006 8:24 am
Posts: 35
If you don't want to lock the object to a new session you could always initialize the collection before you disconnect it from the NHibernate session.


Top
 Profile  
 
 Post subject: Idea but HttpSessionState is nice to have slim
PostPosted: Fri Sep 21, 2007 2:01 pm 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
Thanks for your answer!

That was a possibility, but i would like to keep my HttpSession slim, it suits me well that the data is lazyloaded in places used and slim when transferred around.

I would like to hear how people would achieve this using the second-level cache, or other good suggestions


Top
 Profile  
 
 Post subject: Re: Idea but HttpSessionState is nice to have slim
PostPosted: Sun Jan 27, 2008 9:21 pm 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
deleted


Top
 Profile  
 
 Post subject: Re: HttpSessionState and persistent objects
PostPosted: Sun Jan 27, 2008 11:05 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
jta wrote:
Here comes the catch. A product has a lazyloaded collection which is only needed when showing the contents of the shoppingbasket, but the session is now lost. So i have to reattach the Product objects from HttpSessionState to my current ISession using ISession.Lock(myProduct, LockMode.None).


The main benefit I could see of the second-level cache in most instances is the fact that you don't need to handle your own cache expiry. In your specific instance, since you need to manually control some aspect of the retrieval, I think it would be easier to just use the session context.

I do have a question, though. If you have a collection that only needs to be shown on certain pages, would it maybe be cleaner to not lazy-load the collection? Rather, just load the collection external to the Product.

BasketService.GetBasketItems(parentId) or something like that... then you wouldn't need to worry about manually re-attaching the Product.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.