-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Optimistic Concurrency control in web applications.
PostPosted: Mon Jul 19, 2004 7:44 pm 
Newbie

Joined: Mon Jul 19, 2004 7:06 pm
Posts: 2
Location: Melbourne
I would just like to go over the functioning of version control.
We use Hibernate 2.1.3 to MySQl 4.0.18 in a three tier (Struts/ Spring /Hibernate) system.

The object data is stored in ActionForms between http sessions.

So to save the changes in the ActionForm back to the database,
when the object has been modified by a previous session,
we go through the following steps in the service layer:

1. locate the hibernate object using the id from the ActionForm
2. copy the data from the ActionForm into the Hibernate model object
3. save the model object with changes

Here's the code:

Note we have version tag (type integer) on the modified field...

public Object saveUser(UserFormEx obj) throws Exception {
User oldUser = dao.getUser(obj.getId());
System.out.println("Old from database = "+oldUser.getModified());
System.out.println("In from form = "+obj.getModified());
copyToUser(obj,oldUser);
System.out.println("After copy = "+oldUser.getModified());
dao.saveUser(oldUser);
System.out.println("After Save = "+oldUser.getModified());
return convertUser(oldUser);
}

The output from this function is:
Old from database = 10
In from form = 9
After copy = 9
After Save = 11

I would have expected as the modified field of the form is not equal to current (oldUser) so a Stale Object Exception would be thrown.

Checking the SQL an update where id = ? and modified = ? is successful and any modified user data is saved.
The obvious answer being hibernate saves the old modified field and overwriting it in the copyToUser method does nothing...

The solution is for us is to do the check in the application, however I was wondering why we can't change the modified field forcing the stale exception?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.