This is similar to How to escape reserved words in Hibernate's HQL. But I use JPA, so the solution isn't applicable.
So, how can I escape HQL keywords in JPA?
Example query: (count
is the offending.)
em.createQuery("INSERT INTO Count (id, count) SELECT 1, ?").setParameter(1, id).executeUpdate();
There's this jira HHH-3811, still open. Not sure if relevant since it's about SQL keywords, not HQL keywords.
You could try something like this:
em.createQuery("INSERT INTO Count c (c.id, c.count) SELECT 1, ?").setParameter(1, id).executeUpdate();
That should make it clear to JPA that you mean properties, not keywords.
来源:https://stackoverflow.com/questions/14619630/jpa-hibernate-escaping-hql-keywords