For JPA2 support, I propose that Hibernate LockMode support the
following equivalents of JPA2 LockModeType locks:
LockMode.OPTIMISTIC (READ)
LockMode.OPTIMISTIC_FORCE_INCREMENT (WRITE)
LockMode.PESSIMISTIC_READ
LockMode.PESSIMISTIC_WRITE
LockMode.PESSIMISTIC_FORCE_INCREMENT
Hibernate already supports NONE, so that doesn't need to be added. JPA2
defaults to LockModeType NONE.
JPA1 READ + WRITE will be supported respectively via LockMode.OPTIMISTIC
+ LockMode.OPTIMISTIC_FORCE_INCREMENT.
With this change, Hibernate (native (better term?)) applications would
be able to request JPA2 like locks. This also means that JPA2
applications running with the Hibernate Entity Manager, will see similar
locking behavior as native applications.
Pros:
- Application developers will have a consistent set of locking options
in their JPA2 based applications and native Hibernate applications.
- This helps the application developer to prepare their native Hibernate
application to migrate to JPA2.
Cons:
- This ties Hibernate core locking internals to the JPA2 specification.
As JPA continues to evolve, Hibernate core should follow in lockstep.
Although, that is not a hard requirement.
- An alternative would be introducing low level locking primitives that
could be combined to support JPA2 style locks. I can explore this path
if there is strong push back to the above proposal.
Comments?
Scott