在JPA中使用保留的JPQL关键字 [英] Using reserved JPQL keywords with JPA

查看:277
本文介绍了在JPA中使用保留的JPQL关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Group的实体类,NetBeans警告我实体表名是一个保留的Java Persistence QL关键字。

I have an entity class called "Group" and NetBeans warns me "The entity table name is a reserved Java Persistence QL keyword".

类似的情况是使用保留的SQL关键字。

A similar case would be the use of reserved SQL keywords.

这个名字会被转义吗?是否使用不同的表名解决了问题@Table(name =otherName)。或者我应该重命名该类?

Will this name be escaped? Would the use of a different table name solve the problem @Table(name="otherName"). Or should I rename the class?

推荐答案


此名称是否会被转义?

Will this name be escaped?

JPA规范中有这样说,如果您的提供商这样做,这是提供者特定的。

There is nothing in the JPA spec that says so, if your provider does, this is provider specific.


使用不同的表名是否能解决问题@Table(name =otherName)

Would the use of a different table name solve the problem @Table(name="otherName")

显然,它会(只要你不使用另一个保留关键字)。但是,如果您使用的是JPA 2.0提供程序,则有一种标准方法可以使用双引号来转义数据库对象名称:

Obviously, it would (as long as you don't use another reserved keyword of course). But if you are using a JPA 2.0 provider, there is a standard way to get a db object name escaped, with double quotes:

@Table(name="\"Group\"")

在JPA 1.0中,有没什么标准,这取决于你的JPA提供商。例如,Hibernate使用反引号:

In JPA 1.0, there is nothing standard, it depends on your JPA provider. For example, Hibernate uses backticks:

@Table(name="`Group`")




或者我应该重命名该类吗?

Or should I rename the class?

没有。实体的表名默认为实体名称,但您可以使用我们看到的 @Table 注释来控制它。因此无需更改实体的类名。

No. The table name of an entity defaults to the entity name but you can control it using the @Table annotation as we saw. There is thus no need to change the class name of your entity.

这篇关于在JPA中使用保留的JPQL关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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