我的以下 native 查询不起作用:
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 WARN [org.hibernate.util.JDBCExceptionReporter]
SQL Error: 1064, SQLState: 42000 (http-0.0.0.0-8543-3:)
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:)
最佳答案
对于更新基本上会在行上加锁,要使用 JPA 实现相同的效果,您需要使用 Lock Modes 。要设置锁定,您可以使用 EntityManager 或 TypeQuery 并使用 LockModeType.PESSIMISTIC_WRITE。
关于java - 选择更新不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27446755/