JPAQuery with select for update?

1,756 views
Skip to first unread message

Desert

unread,
Aug 4, 2015, 10:56:58 AM8/4/15
to Querydsl
How to build a select...for update skip locked with JPAQuery?

This does not work:

JPAQuery query = new JPAQuery(entityManager);
query.getMetadata().addFlag(new QueryFlag(Position.END, "\nFOR UPDATE SKIP LOCKED "));
        return query.from(table).where(table.ok.eq(false))
                    .limit(1).uniqueResult(table);


timowest

unread,
Aug 4, 2015, 3:09:24 PM8/4/15
to Querydsl
You can use query.setLockMode(...) to set the lock mode for the query. For example using LockModeType.PESSIMISTIC_WRITE.

Desert

unread,
Aug 5, 2015, 2:36:10 AM8/5/15
to Querydsl
Thank you for the fast response. This will generate select ... for update, but I want to use select .... for update skip locked (Oracle), is this possible with querydsl/JPA?

timowest

unread,
Aug 5, 2015, 1:10:50 PM8/5/15
to Querydsl
I am not sure. That depends on how your JPA provider maps the lock modes to the RDBMS engine.
Reply all
Reply to author
Forward
0 new messages