在 JPA 中使用保留的 JPQL 关键字 [英] Using reserved JPQL keywords with JPA
问题描述
我有一个名为Group"的实体类,NetBeans 警告我实体表名称是保留的 Java Persistence QL 关键字".
类似的情况是使用保留的 SQL 关键字.
这个名字会被转义吗?使用不同的表名会解决问题@Table(name="otherName").或者我应该重命名类?
这个名字会被转义吗?
JPA 规范中没有说明这一点,如果您的提供者这样做,则这是特定于提供者的.
<块引用>使用不同的表名是否可以解决问题@Table(name="otherName")
显然,它会(当然,只要您不使用其他保留关键字).但是,如果您使用的是 JPA 2.0 提供程序,则有一种标准方法可以使用双引号将 db 对象名称转义:
@Table(name=""Group"")
在 JPA 1.0 中,没有任何标准,这取决于您的 JPA 提供商.例如,Hibernate 使用反引号:
@Table(name="`Group`")
<块引用>
或者我应该重命名类?
没有.实体的表名称默认为实体名称,但您可以使用我们看到的 @Table
注释来控制它.因此无需更改实体的类名.
I have an entity class called "Group" and NetBeans warns me "The entity table name is a reserved Java Persistence QL keyword".
A similar case would be the use of reserved SQL keywords.
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?
There is nothing in the JPA spec that says so, if your provider does, this is provider specific.
Would the use of a different table name solve the problem @Table(name="otherName")
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"")
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?
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屋!