With versioning hibernate increments the version number each time. I believe this is prefrered to the timestamp method, but I think hibernate supports both.

(off the top of my head) I have a struts form which holds the fields etc plus the object I loaded from Hibernate. I use DispatchLookUp actions so that all of my actions are selected from the button pressed eg it adds a dispatch=save, or dispatch=overwrite to decide which action to perform. The save action would normally reconnect the hibernate session, start a hibernate transaction, get the object from the form, populate the object properties from the form fields, and end the transaction.

To overwrite (dispatch=overwrite), I think I throw the current hibernate session away, create a new one, load a new object using the objects id (this should get the latest version from the db), start transaction and do the same as the save above.


David Erickson wrote:


I have done this.  Hibernate supports versioning (using a version number
column), if you use this Hibernate can make sure the changes are not
overwritten.

The basic process is:
1. Hibernate session A loads object A1 (with identifier 1234)
2. Hibernate session B loads object B1 (also with identifier 1234)
3. Session A modifies object A1 and saves it
4. B modifies object B1 and attempts to save it
5. Hibernate will detect the version number for the object has changed
and generate an exception (StaleObjectStateException)
6. Catch this exception, close the hibernate session, return an error
message to the user using ActionErrors etc

I also have a refresh button so that at any time the user can press
refresh which reloads the object from hibernate so it is up to date.
When I return my stale object error I also allow the user to either
refresh (loses the users changes), cancel (do nothing, return to parent
menu), or overwrite. Overwrite can attempt to overwrite the changes by
reloading the new object, but use the posted field changes to update and
then save the object.



Yes I figured this out just barely, rather I used timestamp instead of version (are there any drawbacks to that?). I am interested in doing exactly what you did, but how did you go about overwriting the things that have been changed?

Thanks,
David


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




--

Jason Lea



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



Reply via email to