I added another zip with a test for reattachment too:
entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
Session session = entityManager.unwrap( Session.class );
session.buildLockRequest( LockOptions.NONE )
.setLockMode( LockMode.PESSIMISTIC_WRITE )
.setScope( true )
.lock( person );
entityManager.getTransaction().commit();
entityManager.close();
which generates this query:
select
id
from
Person
where
id =? for update
So, the lock scope is never extended to the joined table. I think this could be a very handy feature and it's important to have it since it's demanded by the JPA specs. |