Toplink supports nested Unit of Work sessions, which come in
very handy to "undo" some persistence state changes.
Example:
(1) Create a new window and a new UoW, make some changes
to the object graph
(2) Create a dialog and a child UoW from the window's UoW,
make some more changes to the object graph
(3a) Press "Save" in the dialog -> changes in the child UoW are
merged into the parent UoW. No database yet, all in memory.
(3b) Press "Cancel" in the dialog -> changes in the child UoW
are thrown out, and the parent UoW is in the same state as before
the dialog was opened
Since Hibernate doesn't support this, I wonder if there is a way to
solve this problem in a similar fashion. Maybe something like this:
session.mark();
.... make some changes to objects, etc...
session.reset();
Calling session.reset() restores the persistence state to the time
session.mark() was called.
Hibernate could save the persistence state at mark(), and clear
it on commit(), flush(), or rollback().
Looking at the Hibernate 3.x source, serializing a Session object
also serializes the SessionFactory object. So mark() and reset()
could not be implemented by serializing the session to a buffer,
then later deserializing it from that buffer, right?
SessionImpl contains the PersistenceState object. Is it enough to
just serialize the PersistenceState object on mark(), then on
reset() deserialize it again?
How do others deal with this use case?
Thank's in advance.
|