views:

1100

answers:

1

I'm learning Grails/GORM and as I've understood it the current best practice is not to store domain objects in the session (see http://jira.codehaus.org/browse/GRAILS-978 for a potential fix).

The workaround is simple; simply store the reference id for the domain object in the session, and then re-retrieve the object using on the next request.

My question is: why is it the case that domain objects cannot be stored safely in the session? I'm trying to understand the technicalities behind it.

Thanks!

+6  A: 

One of my concerns about this is that GORM (I would say Hibernate) uses open-session-in-view pattern for each request, where the working Hibernate's session will be closed and flushed in the end of it.

Storing GORM objects in HTTP session means detaching the object from the previous Hibernate session, and re-attaching it to the newly created session. This may cause conflict between two versions of the object.

chanwit