Ondra Žižka Ondra Žižka - 10 months ago 72
Java Question

JPA/Hibernate: How to use INSERT 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, ?]

How should the query look like?

Does it matter that I use JPA API but HQL actually? JPQL doesn't support

Using Hibernate 4.1.6 in JBoss AS 7.1.2.

Reference: http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch11.html#d5e2637

Answer Source

Since count is a reserved word, adding square brackets around it like [count] will work.