On Jun 19, 2007, at 4:21 PM, carlos f wrote:

Norman Franke wrote:

My application only uses detached objects that it persists in the client page for change detection (to determine if the record they were editing
changed while they were editing, which I flag as an
error.)

. . .

The first call to getSession()  creates a HIbernate session, which is
closed when the page is done
rendering.


Since the detached object appears to be persisted on the client side, the hibernate sessions only exist for the rendering of a single page and the session is closed when the page is done processing, it appears as if the detached object should be isolated to a single hibernate session at a time. If that is true, I was interested in his method/motivation for optimistic locking and cloning the detached object graphs for update. If it isn't,
how?

I can't lock the object between requests, so I just verify the data didn't change. So, once the user submits their changes, I verify that the current record as stored in the DB is the same as the one persisted in the client. If so, I allow the save to happen. If not, I display an error.

Norman Franke wrote:

my DAO has an "assertUnchanged" method that throws an exception if the two
objects differ, e.g. my detached object and the one read from the
database. In this case, I tell the user that someone else changed their
record  and their changes have been lost.


I was interested in knowing more about the implementation of
"assertUnchanged" - for all I know his entities could have mapped version
attributes and "assertUnchanged" could be calling
hibernateSession.lock(detachedInstance, LockMode.READ). If it isn't, I just
want to know why.  The question about cloning is along similar lines.

assertUnchanged takes two objects, and compares them via the equals() method. My POJOs have an equals method that compares the fields I'm interested in (i.e. not auto generated data or relationships.) This method was auto generated by Hibernate Tools. It does throw an exception if they are not the same.

-Norman



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to