且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在JPA中使用保留的JPQL关键字

更新时间:2022-12-18 13:27:41


此名称是否会被转义?

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.