I am new to Hibernate and working on a web project that uses it.
I have an object called area that has a date object(java.sql.Timestamp) attribute modifiedDate. When I create a new object modifieDate is null and after send it down to getHibernateTemplate().saveOrUpdate(area); in my own class that extends org.springframework.orm.hibernate3.support.HibernateDaoSupport it is set with current timestamp and saved in the database. In the database it is saved as a datetime.
My problem is most of the time the object is updated with a Date that is 1 millisecond off compared to what it is saved as in the database, this leads to this exception if anything is attempted updated without reloading the page:
an org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)
There are no problems with the correct date when getting the object from database subsequent, it is only at creation it gets the wrong value.
Is there a way to get the correct modifiedDate at SaveOrUpdate?
Incase it is needed the mapping uses <timestamp name="modifiedDate" column="ModifiedDate"/> and all test are run on localhost with everything running on the same machine.
I already have a work around, by calling getHibernateTemplate().refresh(area); right after the saveOrUpdate I get the right timestamp, but I would still like to know if there is a way to get the correct modifiedDate at saveOrUpdate.