I use tiemstamp to auto version. the map file for timestamp perperty like this: <timestamp name="updateTime" column="更新時刻"/>
The type in model object is java.util.Date, in DB is date.
When execute to transaction.commit() StaleObjectStateException thrown.
Code:
beginTransaction();
ConstructionOrder order = new ConstructionOrder();
order.setServiceAreaCode("1");
order.setServiceContractCode("2");
order.setContractYear("2006");
order.setCnsYmd(new Date(2006,10,1));
order.setRecodeNo(new Integer(4));
order.setOrderSourceCode("3");
session.save(order);
session.flush();
Criteria criteria = session.createCriteria(ConstructionOrder.class);
criteria.add(Restrictions.eq("serviceAreaCode", "1"));
criteria.add(Restrictions.eq("serviceContractCode", "2"));
criteria.add(Restrictions.eq("contractYear", "2006"));
criteria.add(Restrictions.eq("orderSourceCode", "3"));
List list = criteria.list();
order = (ConstructionOrder) list.get(0);
order.setAddress("sss");
session.update(order);
transaction.commit();
2006-08-29 18:04:31,125 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] - Could not synchronize database state with session
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [jp.co.comsys.usss.domain.order.model.ConstructionOrder#jp.co.comsys.usss.domain.order.model.ConstructionOrder@8312fa51]
at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1635)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2208)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2374)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:91)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at jp.co.comsys.usss.persistence.hibernate.ConstructionDAO.testCRUD(ConstructionDAO.java:381)
at jp.co.comsys.usss.domain.construction.ConstructionLedger.main(ConstructionLedger.java:576)
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [jp.co.comsys.usss.domain.order.model.ConstructionOrder#jp.co.comsys.usss.domain.order.model.ConstructionOrder@8312fa51]
at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1635)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2208)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2374)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:91)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at jp.co.comsys.usss.persistence.hibernate.ConstructionDAO.testCRUD(ConstructionDAO.java:381)
at jp.co.comsys.usss.domain.construction.ConstructionLedger.main(ConstructionLedger.java:576)
org.hibernate.HibernateException: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [jp.co.comsys.usss.domain.order.model.ConstructionOrder#jp.co.comsys.usss.domain.order.model.ConstructionOrder@8312fa51]
at jp.co.comsys.usss.persistence.hibernate.ConstructionDAO.testCRUD(ConstructionDAO.java:385)
at jp.co.comsys.usss.domain.construction.ConstructionLedger.main(ConstructionLedger.java:576)
Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [jp.co.comsys.usss.domain.order.model.ConstructionOrder#jp.co.comsys.usss.domain.order.model.ConstructionOrder@8312fa51]
at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1635)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2208)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2374)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:91)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at jp.co.comsys.usss.persistence.hibernate.ConstructionDAO.testCRUD(ConstructionDAO.java:381)
... 1 more
Code: