Hi All,
In Hibernate Session there is a method get(Class klass, Serializable id, LockMode lockMode). Why is the JPA EntityManager missing an analogous method?
For example, in order to perform a "select for update" in JPA it is needed to get an entity first and then lock it:
Employee emp = em.find(Employee.class, 123L);
em.lock(emp, LockModeType.READ);
That will result in 2 selects:
1. select ... from Employee
2. select ... from Employee for update.
In Hibernate, however, I could just write:
session.get(Employee.class, 123L, LockMode.UPGRADE);
which will just run a "select for update" and return an entity.
So, my question is whether it is possible to get an entity in JPA and perform a "select for update" at the same time? Or am I missing somethong.
Cheers,
Dimitrio
|