-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem With Optimistic locking - Please help
PostPosted: Mon Apr 09, 2007 11:55 pm 
Newbie

Joined: Mon Apr 09, 2007 11:48 pm
Posts: 1
In order to make hibernate do the Optimistic Locking we are setting the optimistic-lock="version" and the <timestamp> attribute in the configuration xml (cfg.xml).

If there is an optimistic-lock value set and when user tries to modify and save a record, in the update statement generated by hibernate, it will put a where clause with the timestamp column (column name mentioned in the <timestamp> attribute) and the primary key condition.

During the initial load of that record, hibernate stores this timestamp value somewhere in its memory and retrieves it back to add it to the where clause of the update statement.

If the update was successful, JDBC call returns the affected record count.

If the update was not successful, JDBC call returns 0 and hibernate throws a StaleObjectStateException.

Possible reason could be not finding a suitable match as mentioned in the where clause.

By writing an Interceptor class, on load of a record, we could see the value for last_update_date as,

The value coming in POJO is --> 2007-02-19 18:09:20.187119

Actual value in Database is --> 2007-2-19 18.9.20.187119000 -6:0

In database, the last_update_date is TIMESTAMP WITH TIMEZONE where as in POJO it is only TIMESTAMP.

When tried converting the java.sql.timestamp value in POJO to java.util.date, then we see the following output.

Converted to java.util.date --> Mon Feb 19 18:09:20 GMT+05:30 2007

Since the time zone details wasn’t there in the POJO field; when converted to date, it picked up the Virtual Machines default time zone.

Assuming that because of this the where clause is failing and hibernate is saying that the record is stale.

Can somebody please help me figure out a solution for this problem?
Please revert back If you need more inputs.

Your help is really appreiated.
Sajesh


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 13, 2007 3:01 pm 
Newbie

Joined: Wed Mar 08, 2006 6:55 pm
Posts: 1
What database are you using. According to this: <http://www.hibernate.org/80.html>

"At least some versions of the Oracle 9i driver handle JDBC timestamps extremely badly - do not use timestamps for optimistic locking, use version numbers."


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

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.