When EntityManager#find fails while requesting a pessimistic lock with a timeout specified, Hibernate throws org.hibernate.PessimisticLockException, which is converted to javax.persistence.LockTimeoutException by the following code in ExceptionConverterImpl#wrapLockException(HibernateException e, LockOptions):
The resulting LockTimeoutException causes a statement-level rollback.
The same should happen for Query#getResultList and #getSingleResult when the query fails while requesting a pessimistic lock with a timeout specified.
Instead, ExceptionConverterImpl#wrapLockException incorrectly gets called with a null value for lockOptions. As a result, org.hibernate.PessimisticLockException gets converted to javax.persistence.PessimisticLockException, which causes a transaction-level rollback.
The fix should pass the query's LockOptions to ExceptionConverterImpl#wrapLockException, so org.hibernate.PessimisticLockException will be properly converted to javax.persistence.LockTimeoutException.
Fixed in master branch.
Fixed in 5.3 branch as well.