Select for update skip locked from JPA level

前端 未结 3 1525
心在旅途
心在旅途 2021-02-19 06:42

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         


        
3条回答
  •  悲哀的现实
    2021-02-19 06:51

    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");
        }});
    

提交回复
热议问题