We can make domain objects work across the session with a simple trick.
1. Override the add/put methods on HttpSession to detect domain class instances being added to the session
2. Instead of the instance, put in its id in a special serializable object that contains the ID and CLASSNAME of the original domain class.
3. Put the domain instance into the REQUEST context, using a special name like _grails_domain_ATTRIBNAME
The object ID is now safely in the session, and the request has a ref to the instance.
When retrieving the object from the session:
1. Get the attribute from session. If it is our special wrapper object, ask the request if it has _grails_domain_ATTRIBNAME.
2. If it does, just return this (this allows access to the var during the request in which it was added to the session)
3. If it does not, extract CLASSNAME from our wrapper, do CLASSNAME.get(ID) and put this value into the REQUEST context again as _grails_domain_ATTRIBNAME
4. Return the loaded instance.
This should give us transparent and scalable session access to domain object.s