michael wrote:
You can use Date and use type="timestamp" in your mapping
Hi,
I am using DATE for the database field and type="timestamp" for the corrsponding mapping in the HBM . The java datatype is java.util.date
I am able to save a record into th DB with this setup. However when I
access the same record, update it and try to save it back, I have the following exception :
org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.xx.xx.Reason#4]; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.xx.xx.Reason#4]
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.xx.xx.Reason#4]
....................................
..................................
........ 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.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
The query for the update is as follows:
Hibernate: update WW_APPMT_REASON set MODIFIED_DT=?, CREATED_BY=?, CREATED_DT=?, MODIFIED_BY=?, DESCRIPTION=? where REASON_ID=? and MODIFIED_DT=?
2006-09-18 11:46:25,765 [main] DEBUG org.hibernate.type.TimestampType - binding '2006-09-18 11:46:25' to parameter: 1
2006-09-18 11:46:25,765 [main] DEBUG org.hibernate.type.LongType - binding '20' to parameter: 2
2006-09-18 11:46:25,765 [main] DEBUG org.hibernate.type.TimestampType - binding '2006-09-18 11:45:22' to parameter: 3
2006-09-18 11:46:25,765 [main] DEBUG org.hibernate.type.LongType - binding '21' to parameter: 4
2006-09-18 11:46:25,765 [main] DEBUG org.hibernate.type.StringType - binding 'Vaccination' to parameter: 5
2006-09-18 11:46:25,765 [main] DEBUG org.hibernate.type.LongType - binding '6' to parameter: 6
2006-09-18 11:46:25,765 [main] DEBUG org.hibernate.type.TimestampType - binding '2006-09-18 11:45:22' to parameter: 7