I use getHibernateTemplate().merge(obj)
to persist my obj
in the db (once the transaction completes).
My code goes something like this:
Foo obj = getHibernateTemplate().merge(obj);
My Foo table (corresponding to Foo class
) has a version column. Foo is version controlled and Hibernate updates the version after the transaction (controlled by Spring) completes.
Now, after the transaction, the obj still shows the old version while the db has the incremented version. I understand that the version is physically set only after the transaction completes.
If I update the obj now and try to 'merge
' again, it throws StaleObjectException
(expected).
Question : How can I update this object to get the latest version. Why should Merge not give me the latest updated object. Will I have to load the object again?