Ondra Žižka
Ondra Žižka

Reputation: 46796

JPA/Hibernate: How to use INSERT JPQL?

This JPQL

em.createQuery("INSERT INTO Count (id, count) SELECT 1, ?").setParameter(1, id).executeUpdate();

throws

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 INSERT.

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

Upvotes: 1

Views: 2769

Answers (1)

Mukus
Mukus

Reputation: 5033

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

Upvotes: 4

Related Questions