Hi, we have a big problem regarding merge()
We use version property for optimisting locking
and we are saving detached objects using merge()
Because consecutive saves on the same detached objects can occur,
we're trying to keep the version updated, by reading it from the returned persistent instance of the same object.
This is supposed to be the current state of the object (as the api states), BUT it is not !!! The version of the returned instance it is the OLD one.
So when trying to save the object again we're getting a StaleObjectStateException
Hibernate version: 3.2.2.ga
Base DAO
We are using org.springframework.orm.hibernate3.support.HibernateDaoSupport
Code:
public abstract class AppBaseDAOHibernate<E extends BaseEntity>
extends HibernateDaoSupport {}
Save methodCode:
public BaseEntity save(final E entity) {
BaseEntity savedEntity = (BaseEntity) getSession().merge(entity);
entity.setXversion(savedEntity.getXversion());
return savedEntity;
}
Please help!