JPA/Hibernate: Escaping HQL keywords

江枫思渺然 提交于 2019-12-02 19:17:00

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!