I am new to Hibernate and am working on a web project that uses it.
I have an object called a scope that has a date ( java.sql.Timestamp ) modifiedDate attribute. When I create a new modifieDate object it is null and after sending it to getHibernateTemplate().saveOrUpdate(area); in my own class, which extends org.springframework.orm.hibernate3.support.HibernateDaoSupport , it is set with the current timestamp and stored in the database. It is saved as a datetime in the database.
My problem in most cases, when an object is updated with a date equal to 1 millisecond, compared with the fact that it is stored as in a database, this leads to this exception if something tries to update without reloading the page:
an org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)
There is no problem with the correct date when you subsequently retrieve the object from the database, only when it is created it gets the wrong value.
Is there a way to get the correct modifiedDate in SaveOrUpdate?
If necessary, a mapping is used that uses <timestamp name="modifiedDate" column="ModifiedDate"/> , and all tests are run on the local host with all running on the same machine.
I already have work by calling getHibernateTemplate().refresh(area); right after saveOrUpdate, I get the correct timestamp, but I still would like to know if there is a way to get the correct change in the saveOrUpdate file.
Blem
source share