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