选择更新不起作用 [英] Select for update not working
问题描述
我的以下本机查询不起作用:
My following native query is not working:
Query createNativeQuery = entityManager.createNativeQuery(
"select id from cscache where id=? for update ");
环境详细信息:
- Mysql 5.6
- Jboss 5.1
- JPA 1.0
错误:
2014-12-12 10:20:14,581警告[org.hibernate.util.JDBCExceptionReporter]
2014-12-12 10:20:14,581 WARN [org.hibernate.util.JDBCExceptionReporter]
SQL错误:1064,SQLState:42000(http-0.0.0.0-8543-3:)
SQL Error: 1064, SQLState: 42000 (http-0.0.0.0-8543-3:)
2014-12-12 10:20:14,581错误[org.hibernate.util.JDBCExceptionReporter] 您的SQL语法有误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行(http-0.0.0.0-8543-3 :)的'limit 2'附近使用
2014-12-12 10:20:14,581 ERROR [org.hibernate.util.JDBCExceptionReporter] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 2' at line 1 (http-0.0.0.0-8543-3:)
推荐答案
我实际上尚未在休眠状态下进行更新,但我相信您可以(并且应该?)在Session或查询对象上进行此操作.为什么不让冬眠做它而不是执行本机查询呢? 根据有关锁定的文档(第5章:锁定,您可以在会话或查询上设置锁定模式.
I haven't actually done a for update in hibernate, but I believe you can (and should?) do it on the Session or query object. Why not let hibernate do it instead of executing a native query? According to the documentation on locking (Chapter 5: Locking, you can set the lock mode on either the session or the query.
Cscache cscache = (Cscache )session.get( Cscache.class, id, LockOptions.UPGRADE );
指定LockOptions应该导致执行SELECT ... FOR UPDATE.
Specifying the LockOptions should result in a SELECT ... FOR UPDATE being executed.
这篇关于选择更新不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!