JPA / Hibernate:转义HQL关键字 [英] JPA/Hibernate: Escaping HQL keywords

查看:572
本文介绍了JPA / Hibernate:转义HQL关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这类似于如何在Hibernate的HQL中转义保留字词。但是我使用JPA,所以解决方案是不适用的。

This is similar to How to escape reserved words in Hibernate's HQL. But I use JPA, so the solution isn't applicable.

那么,如何在JPA中避免HQL关键字?

So, how can I escape HQL keywords in JPA?

示例查询:( count 是有罪的。)

Example query: (count is the offending.)

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

有这个jira HHH-3811 仍然开放。
不确定是否相关,因为它是关于SQL关键字,而不是HQL关键字。

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();

应该向JPA明确表示属性而不是关键字。

That should make it clear to JPA that you mean properties, not keywords.

这篇关于JPA / Hibernate:转义HQL关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆