I am working on a client/server app with a rich client. I have to deal with concurrent data access and am trying to do so with optimistic locking using versioning. Because I am using a thick client i use a DTOs to pass data back and forth between the server and client. I record the version id in the DTO. To perform an update I:
1)pass the dto back to the server
2) retrieve the hibernate domain object I am updating
3)update the domain object fields with the new values
4)update the version of the domain object to the original one i recorded in the dto
5)process the update
However when you update the domain object's version manually optimistic locking ceases to work. It is as if it ignores that value entirely, i am guessing it maybe just uses the cached version instead. This causes optimistic locking to fail.
I think this is a bug in hibernate. I see that this topic has been brought up several times on this forum for instance:
http://forum.hibernate.org/viewtopic.php?t=955121
I am hoping someone can explain why this does this or maybe this is a known bug?