Using Reserved JPQL Keywords with JPA

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 to use reserved SQL keywords.

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

+7
java java-ee orm jpa jpql
source share
2 answers

Will this name be escaped?

There is none in the JPA specification that says so if your provider does this, it is a specific provider.

Will using a different table name solve the @Table problem (name = "otherName")

Obviously, that would be (unless you use another reserved keyword, of course). But if you are using a JPA 2.0 provider, there is a standard way to get the db escaped object name with double quotes:

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

There is nothing standard in JPA 1.0, it depends on your JPA provider. For example, Hibernate uses backlinks:

 @Table(name="`Group`") 

Or do I need to rename the class?

Not. The default table name of the object is the same as the name of the object, but you can control it using the @Table annotation, as we saw. Thus, there is no need to change the class name of your object.

+11
source share

You do not need to rename the class - and you should not - the name that you choose reflects your domain in the best way, and you should not change it due to the limitations of the tool or frame, if the tool / frame provides a way to avoid a "collision". JPA provides such a method.

+4
source share

All Articles