Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
[b3.0.5[/b]
[b]Mapping documents(Fragment):
<class
name="gov.ca.doj.sins.riss.model.Submission"
table="SUBMISSIONS" select-before-update="true" dynamic-update="true" optimistic-lock="version"
>
...
...
<timestamp name="modifyTimestamp" column="MODIFY_TIMESTAMP" />
[/b]
Hi,
We use modify_timestamp as our managed versioning.
We have a scenario in a web application where we do the following steps:
(1) Retrieve event with id="1234". (called eventDTO1 which reads its values from event POJO) (modify timestamp say 1 pm)
(2) Retrieve another event with same id="1234" (called eventDTO2 which reads its values from event POJO) (modify timestamp say 1:10 pm)
(3) Make some updates in presentation layer to some attributes of eventDTO2 and send it to persistence layer for update. Persistence layer retrieved event POJO and updated its attributes from eventDTO2. Everything is updated succesfully and modify timestamp is updated to current time (say 1:20 pm)
(4) Now make some updates to eventDTO1 and send it to persistence layer, persistence layer retrieved event POJO and updated its attributes from eventDTO1. we expected to see StateObjectStateException but everything gets updated successfully and modify_timestamp is updated to say 1:30 pm (which was when we did update for event)
When I look at the reason why the update went through succesfully, I found that the following query was used:
2005-10-28 13:55:15,969 [main] DEBUG org.hibernate.SQL - update SUBMISSIONS set MODIFY_TIMESTAMP=?, MODIFY_ID=? where ID=? and MODIFY_TIMESTAMP=?
The actual query with values (in pseudo-code) looks like this:
update SUBMISSIONS set MODIFY_TIMESTAMP="1:30 pm", modify_id='ABCD' where is='1234' and MODIFY_TIMESTAMP="1:20 pm";
(this query will always succeed since the value of MODIFY_TIMESTAMP used in where clause is value stored in database (previousState) and not currentState which will be set from presentation layer)
The MODIFY_TIMESTAMP that we should expect to be used in the where clause is the one held in eventDTO1 (which was 1:10 pm)
But the value that was used in MODIFY_TIMESTAMP in where clause was 1:20 pm and not 1:10 pm which would have triggered StaleObjectStateException. 1:20 pm was time when eventDTO2 in step 3 was successfully updated. I found these values reliably by using p6spy.
Hibernate should be using the modify_timestamp value that is coming from presentation layer and not the current modify_timestamp value stored in database.
I am using following attributes in all in hbm xml files:
<class
name="gov.ca.doj.sins.riss.model.Submission"
table="SUBMISSIONS" select-before-update="true" dynamic-update="true" optimistic-lock="version"
>
...
...
<timestamp name="modifyTimestamp" column="MODIFY_TIMESTAMP" />
Note: We posted it to Hibernate JIRA thinking it is a bug, but it has been rejected without any explaination. We are at loss how to use Hibernate's stale data check feature. Please help us otherwise we will end up having to write our own code for this, which we want to avoid.
Anil and Virinder