I am currently stuck on this Optimisitc locking feature provided by hibernate which doesn't seem to work for me.
I have a Domain Object ( DO ) and a Data Transfer Object(DTO) and a property called recordVersion on both of these objects and its defined in the *.hbm file with <version ....> property.
Problem is this:
I read the DO and convert it to DTO and hibernate session closes. DTO then gets passed on to the web layer where user modifies it.
Then when the form is submitted, i read the Domain object from database and convert the DTO to DO.
Which means that if the DTO has the version value = 10 for example thats what the version value on the Domain object would be in the session now after copying DTO properties onto the Domain Object.
But in the database the version value of the Domain object is for example 12,
when i save my DTO that had version value= 10 i would expect hibernate to throw StateObjectStateException but doesn't seem to happen.
What happens is the version value becomes 13 instead.
Any ideas what is going wrong ?