setLockMode() error on JPAUpdateClause with Hibernate 4.3.8

734 views
Skip to first unread message

Michael Tontchev

unread,
May 5, 2015, 1:18:17 PM5/5/15
to quer...@googlegroups.com
I am trying to run

JPAUpdateClause query = new JPAUpdateClause(em, user);
query.set(user.name, "test").setLockMode(LockModeType.PESSIMISTIC_WRITE);
 
However, when I execute this, I get

java.lang.IllegalStateException: Illegal attempt to set lock mode on a non-SELECT query

thrown by org.hibernate.jpa.spi.AbstractQueryImpl.setLockMode(AbstractQueryImpl.java:129)

I'm using Hibernate 4.3.8. Do you think this is a Hibernate bug? There appears to have been a similar bug in 4.3.0, but it was allegedly fixed in 4.3.1.

Thanks!

timowest

unread,
May 5, 2015, 3:57:50 PM5/5/15
to quer...@googlegroups.com
Hi.

This looks like a Hibernate bug. At least no something tht should be controlled on the Queryds level.

Timo

Michael Tontchev

unread,
May 5, 2015, 7:55:08 PM5/5/15
to quer...@googlegroups.com
Okay. I'm looking at the major JPA providers, and every single one besides OpenJPA restricts setLockMode() to only work for select queries:




In fact, it seems like javax itself specifies that

Throws: IllegalStateException - if the query is found not to be a Java Persistence query language SELECT query or a Criteria API query

Am I reading this wrong, or is JPA not supposed to allow lock modes on update queries?

Michael Tontchev

unread,
May 11, 2015, 10:35:49 AM5/11/15
to quer...@googlegroups.com
Bump. Are you sure JPA allows lock modes on update/delete clauses?

timowest

unread,
May 11, 2015, 4:52:37 PM5/11/15
to quer...@googlegroups.com
Looks like you are right. Could you create an issue for it?

Michael Tontchev

unread,
May 11, 2015, 5:07:18 PM5/11/15
to quer...@googlegroups.com
Done!
Reply all
Reply to author
Forward
0 new messages