-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem with timestamp type field
PostPosted: Thu Feb 22, 2007 2:26 pm 
Newbie

Joined: Mon Nov 08, 2004 4:05 am
Posts: 6
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 Trace
Code:
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 5:25 am 
Newbie

Joined: Thu Feb 15, 2007 5:46 am
Posts: 12
Location: Helsinki
try using <version type="timestamp"> instead of <timestamp>.

<timestamp> seems to implement a datetime, and doesn't care about milliseconds.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.