1st solution (detached object):
Step 1: load the object graph you need and close the session
Step 2 (httpRequest 1): the detached object graph may have been updated --> NO PROBLEM, no need to re attach it
Step 3 (httpRequest 2): again the detached object graph may have been updated --> NO PROBLEM, no need to re attach it
Step 4 (httpRequest 3 validation): here just call session.merge(detached root object)
you need to have cascade activated to easily handle this situation and step 1 is important, otherwise you'll need to lock to initialise proxys
2nd solution (long session):
Step 1: load the object graph or root instance (maybe with usefull association uninitialized, nomatter), then you have to disconnect/reconnect at each httpRequest + setFlushMode to NONE
Step 2 (httpRequest 1): the object is still attached, may have been updated but nothing is going to be flushed because of FlushMode
Step 3 (httpRequest 2): the object is still attached, may have been updated but nothing is going to be flushed because of FlushMode
Step 4 (httpRequest 3 validation): here just call session.flush() + commit
This one requires a ServletFilter to manage disconnection/reconnection
So get Hibernate In Action, you'll find usefull things about this.
_________________ Anthony, Get value thanks to your skills: http://www.redhat.com/certification
|