Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing Grails/GORM domain objects in the session - why not?

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!

like image 637
knorv Avatar asked Dec 17 '22 09:12

knorv


1 Answers

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.

like image 117
chanwit Avatar answered Dec 29 '22 10:12

chanwit