Hibernate version: 3.2
Mapping documents:
Code:
<hibernate-mapping>
<class name="com.sample.Order" table="ORDER">
<id column="ORDER_ID" name="id" type="long">
<generator class="com.sample.MyGenerator"/>
</id>
<timestamp column="MODIFIED_DT" name="lastModifiedTime" />
<property column="STATUS" name="status" type="string" />
</class>
</hibernate-mapping>
Name and version of the database you are using:Sybase Anywhere 10
The generated SQL (show_sql=true):Code:
2007-02-22 23:31:12,814 S#61 R#243 [http-9080-Processor23] DEBUG org.hibernate.SQL - update ORDER set MODIFIED_DT=?, STATUS=? where ORDER_ID=? and MODIFIED_DT=?
2007-02-22 23:31:12,815 S#61 R#243 [http-9080-Processor23] DEBUG org.hibernate.type.TimestampType - binding '2007-02-22 23:31:12' to parameter: 1
2007-02-22 23:31:12,815 S#61 R#243 [http-9080-Processor23] DEBUG org.hibernate.type.StringType - binding 'A' to parameter: 2
2007-02-22 23:31:12,817 S#61 R#243 [http-9080-Processor23] DEBUG org.hibernate.type.LongType - binding '20166' to parameter: 3
2007-02-22 23:31:12,817 S#61 R#243 [http-9080-Processor23] DEBUG org.hibernate.type.TimestampType - binding '2007-01-09 10:09:29' to parameter: 4
I have a simple Order entity using which I am prototyping the concurrency check of entity data by hibernate using the modification timestamp.
The problem is that while the data type defined for the attribute is timestamp, the data as saved in the Sybase DB is :
Code:
select * from order where order_id = 20166;
ORDER_ID STATUS MODIFIED_DT
------------------------------------------------------------
20166 A 2007-01-09 10:09:29.765
The MODIFIED_DT column is of type TIMESTAMP in the DB as well. The column contains the milisecond value as well. Hibernate however appears to skip the field when doing a query in the DB as shown above. This is causing a org.hibernate.StaleObjectStateException to happen.
Exception TraceCode:
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.sample.Order#20166]
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 $Proxy41.save(Unknown Source)
at com.sample.ui.CreateOrder.onSave(CreateOrder.java:117)
How can we handle this scenario ? Anything I am doing wrong in my mappings ?
Any inputs would be welcome.
Thanks.