这个 JPQL
em.createQuery("INSERT INTO Count (id, count) SELECT 1, ?").setParameter(1, id).executeUpdate();
抛出
org.hibernate.hql.internal.ast.QuerySyntaxException: expecting OPEN, found ')' near line 1, column 29 [INSERT INTO Count (id, count) SELECT 1, ?]
查询应该是什么样子的?
我使用 JPA API 而实际上使用 HQL 有关系吗? JPQL 不支持 INSERT
。
在 JBoss AS 7.1.2 中使用 Hibernate 4.1.6。
引用:http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch11.html#d5e2637
最佳答案
因为 count
是一个保留字,所以像 [count]
这样在它周围添加方括号就可以了。
关于java - JPA/hibernate : How to use INSERT JPQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14619328/