Using @DynamicUpdate and @OptimisticLockType.DIRTY for Optimistic Locks

We are using Hibernate version 4.2.18 in our application and we are trying to configure Optimistic Locking and tried @Version with Timestamp column and we are facing issues with associated tables and it will take more effort for us to fix the associated entities. So, we have researched on alternate solutions and found an alternate solution with @DynamicUpdate and @OptimisticLocking with OptimisticLockType DIRTY or ALL and completed a quick POC to prove that this is working.

I could see that these annotations are available in Hibernate java doc.
@DynamicUpdate
@OptimisticLocking(type = OptimisticLockType.DIRTY)

Java doc link:
https://docs.jboss.org/hibernate/orm/4.2/javadocs/

But it is not documented as one of the ways to achieve (i.e. alternate to @Version) solution in the Hibernate developer guide documentation.
http://docs.jboss.org/hibernate/orm/4.2/devguide/en-US/html_single/#d5e1239

Can anyone clarify why it is documented as a Optimistic Lock solution? Are there any known issues with using this solution? Are they deprecated in the latest version or going to get removed in any future Hibernate releases?

The 3.x and 4.x User Guides are deprecated and you should use the 5.x ones which we rewrote from scratch.

So, both annotations are documented:

For more details, check out this article as well.

1 Like