Hibernate version:2.1.3
Hi,
I am using timestamp tag to map a property in the persitent class to a Timestamp field of a table in the database. In my code i have a Set(collection) of persistent object which are mapped to this table. My code retrieves the rows from this table and places them in the Set. Later i do some modifications to some obejcts in this set( but i never touch the timestamp field ). Then i pass this entire set to hibernate for persisting.
The problem i encounter is hibernate randomly fails while trying to update this table. The error message that i get is StaleObjectException. I went through the logs and found out that hibernate fires the following query:
###############################################
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.persister.EntityPersister] Updating entity: [com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasure#com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasurePK@e74a94[analysisId=594,analysisVersionId=1,measureId=35,measureVersionId=1]]
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.persister.EntityPersister] Existing version: 2005-02-04 13:08:15.602 -> New version: 2005-02-07 19:36:58.544
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.SQL] update AD_ANALYSIS_MEASURE set UPDATE_DTTM=?, UPDATE_USER=? where ANALYSIS_ID=? and ANALYSIS_VERSION_ID=? and MEASURE_ID=? and MEASURE_VERSION_ID=? and UPDATE_DTTM=?
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.impl.BatcherImpl] preparing statement
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.persister.EntityPersister] Dehydrating entity: [com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasure#com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasurePK@e74a94[analysisId=594,analysisVersionId=1,measureId=35,measureVersionId=1]]
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.TimestampType] binding '07 February 2005 19:36:58' to parameter: 1
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.StringType] binding null to parameter: 2
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.IntegerType] binding '594' to parameter: 3
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.IntegerType] binding '1' to parameter: 4
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.IntegerType] binding '35' to parameter: 5
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.IntegerType] binding '1' to parameter: 6
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.TimestampType] binding '04 February 2005 13:08:15' to parameter: 7
2005-02-07 19:36:58,715 ERROR [net.sf.hibernate.StaleObjectStateException] An operation failed due to stale data
net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasure instance with identifier: com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasurePK@e74a94[analysisId=594,analysisVersionId=1,measureId=35,measureVersionId=1]
###############################################
In the log i saw that hibernate is truncating the milliseconds part of the timestamp field. I thought this might be the reason why hibernate doesnt find the appropriate row to update and hence throws exception.
But, if my set had, say, 5 objects then the update occurs successfully on some of these objects( even though the truncating of the timestamp field is done) but it fails on other objects in the set. Also, this behavior is not consistent. Sometimes none of the objects are successfully updated(even though i dont change the code).
Below is the log for this case:
###############################################
2005-02-07 19:36:58,669 DEBUG [net.sf.hibernate.persister.EntityPersister] Updating entity: [com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasure#com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasurePK@ab2790[analysisId=594,analysisVersionId=1,measureId=34,measureVersionId=1]]
2005-02-07 19:36:58,669 DEBUG [net.sf.hibernate.persister.EntityPersister] Existing version: 2005-02-04 13:08:15.587 -> New version: 2005-02-07 19:36:58.544
2005-02-07 19:36:58,669 DEBUG [net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
2005-02-07 19:36:58,669 DEBUG [net.sf.hibernate.SQL] update AD_ANALYSIS_MEASURE set UPDATE_DTTM=?, UPDATE_USER=? where ANALYSIS_ID=? and ANALYSIS_VERSION_ID=? and MEASURE_ID=? and MEASURE_VERSION_ID=? and UPDATE_DTTM=?
2005-02-07 19:36:58,669 DEBUG [net.sf.hibernate.impl.BatcherImpl] preparing statement
2005-02-07 19:36:58,669 DEBUG [net.sf.hibernate.persister.EntityPersister] Dehydrating entity: [com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasure#com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasurePK@ab2790[analysisId=594,analysisVersionId=1,measureId=34,measureVersionId=1]]
2005-02-07 19:36:58,669 DEBUG [net.sf.hibernate.type.TimestampType] binding '07 February 2005 19:36:58' to parameter: 1
2005-02-07 19:36:58,669 DEBUG [net.sf.hibernate.type.StringType] binding null to parameter: 2
2005-02-07 19:36:58,669 DEBUG [net.sf.hibernate.type.IntegerType] binding '594' to parameter: 3
2005-02-07 19:36:58,669 DEBUG [net.sf.hibernate.type.IntegerType] binding '1' to parameter: 4
2005-02-07 19:36:58,669 DEBUG [net.sf.hibernate.type.IntegerType] binding '34' to parameter: 5
2005-02-07 19:36:58,669 DEBUG [net.sf.hibernate.type.IntegerType] binding '1' to parameter: 6
2005-02-07 19:36:58,669 DEBUG [net.sf.hibernate.type.TimestampType] binding '04 February 2005 13:08:15' to parameter: 7
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.impl.BatcherImpl] closing statement
**********************SUCCESSFUL**********************
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.persister.EntityPersister] Updating entity: [com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasure#com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasurePK@16469e8[analysisId=594,analysisVersionId=1,measureId=17,measureVersionId=1]]
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.persister.EntityPersister] Existing version: 2005-02-04 13:08:15.587 -> New version: 2005-02-07 19:36:58.544
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.SQL] update AD_ANALYSIS_MEASURE set UPDATE_DTTM=?, UPDATE_USER=? where ANALYSIS_ID=? and ANALYSIS_VERSION_ID=? and MEASURE_ID=? and MEASURE_VERSION_ID=? and UPDATE_DTTM=?
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.impl.BatcherImpl] preparing statement
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.persister.EntityPersister] Dehydrating entity: [com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasure#com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasurePK@16469e8[analysisId=594,analysisVersionId=1,measureId=17,measureVersionId=1]]
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.type.TimestampType] binding '07 February 2005 19:36:58' to parameter: 1
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.type.StringType] binding null to parameter: 2
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.type.IntegerType] binding '594' to parameter: 3
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.type.IntegerType] binding '1' to parameter: 4
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.type.IntegerType] binding '17' to parameter: 5
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.type.IntegerType] binding '1' to parameter: 6
2005-02-07 19:36:58,700 DEBUG [net.sf.hibernate.type.TimestampType] binding '04 February 2005 13:08:15' to parameter: 7
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.impl.BatcherImpl] closing statement
**********************SUCCESSFUL AGAIN **********************
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.persister.EntityPersister] Updating entity: [com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasure#com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasurePK@e74a94[analysisId=594,analysisVersionId=1,measureId=35,measureVersionId=1]]
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.persister.EntityPersister] Existing version: 2005-02-04 13:08:15.602 -> New version: 2005-02-07 19:36:58.544
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.SQL] update AD_ANALYSIS_MEASURE set UPDATE_DTTM=?, UPDATE_USER=? where ANALYSIS_ID=? and ANALYSIS_VERSION_ID=? and MEASURE_ID=? and MEASURE_VERSION_ID=? and UPDATE_DTTM=?
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.impl.BatcherImpl] preparing statement
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.persister.EntityPersister] Dehydrating entity: [com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasure#com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasurePK@e74a94[analysisId=594,analysisVersionId=1,measureId=35,measureVersionId=1]]
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.TimestampType] binding '07 February 2005 19:36:58' to parameter: 1
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.StringType] binding null to parameter: 2
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.IntegerType] binding '594' to parameter: 3
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.IntegerType] binding '1' to parameter: 4
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.IntegerType] binding '35' to parameter: 5
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.IntegerType] binding '1' to parameter: 6
2005-02-07 19:36:58,715 DEBUG [net.sf.hibernate.type.TimestampType] binding '04 February 2005 13:08:15' to parameter: 7
2005-02-07 19:36:58,715 ERROR [net.sf.hibernate.StaleObjectStateException] An operation failed due to stale data
net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasure instance with identifier: com.teradata.crm.analysis.hibernateobject.AdAnalysisMeasurePK@e74a94[analysisId=594,analysisVersionId=1,measureId=35,measureVersionId=1]
**********************BUT FAILED **********************
###############################################
Can someone tell me a solution to this problem.
Thank you.
|