-->
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.  [ 3 posts ] 
Author Message
 Post subject: Reattaching objects stored in HttpSession
PostPosted: Sun Dec 11, 2005 6:56 pm 
Regular
Regular

Joined: Tue Sep 28, 2004 6:34 pm
Posts: 50
I have a Cart object that is stored in HttpSession, it contains products and other Hibernate's persisted objects.

As a natural way of doing things, since I use open session in view pattern - to be precise spring's OpenSessionInView filter, I store whole objects in the cart. As a result I do get occasionally: "Illegal attempt to associate a collection with two open sessions;" or "'NonUniqueObjectException" especially AJAX based stuff is likely to trigger it.

In other words two threads get the same HttpSession and try to reattach object using two different hibernate sessions, for sure one of them will fail at some point.

I know that there are other options:
1. store object's ids - too expensive since creation of cart presentation cost's too much
2. fully initialize objects before storing in HttpSession, too much data to load and store in session
3. long sessions - store Hibernate's session in HttpSession) then disconnect/reconnect, not sure how it is compatible with OpenSessionInView filter
4. synchronize HttpSession (http://forums.hibernate.org/viewtopic.php?p=2218457), I do not think that it is good idea either

Does anyone have a nice strategy of storing hibernate persisted object in HttpSession?

Thanks in advance,
Lukasz


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 7:30 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Synchronize/serialize access to the HttpSession. Hibernate objects in there aren't the only reason to do that.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 4:18 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
"2,3,4" are more expensive than "1." ( you can use global cache optimized for scalability).
5. Store cart on client using URL parameters, hidden form fields, cookies or script variables.


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