In my application - Oracle with JPA (EclipseLink), I\'m using the following expression to lock the subset of the records in some tables:
select * from MY_TABLE w
I know this post is a bit old, but for the record, just as the accepted answer stated, "javax.persistence.lock.timeout" (org.hibernate.cfg.AvailableSettings#JPA_LOCK_TIMEOUT
) set to "-2" (org.hibernate.LockOptions#SKIP_LOCKED
) with Hibernate results in "SKIP LOCKED". However, this can be done at run-time without having to set any global settings.
Since 2.0 JPA allows to pass hints along like so
entityManager.find(MyType.class, id, LockModeType.PESSIMISTIC_WRITE, new HashMap() {{
put("javax.persistence.lock.timeout", "-2");
}});