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?
The Java Persistence Query Language (JPQL) is the query language defined by JPA. JPQL is similar to SQL, but operates on objects, attributes and relationships instead of tables and columns.
For all JPA query objects (except for native SQL queries), you would use pagination through the setMaxResults(int) and setFirstResult(int) methods.
It behaves as a runtime interface between a Java application and Hibernates. It uses Java Persistence Query Language (JPQL) is an object-oriented query language to perform database operations. It uses Hibernate Query Language (HQL) is an object-oriented query language to perform database operations.
In order to define SQL to execute for a Spring Data repository method, we can annotate the method with the @Query annotation — its value attribute contains the JPQL or SQL to execute. The @Query annotation takes precedence over named queries, which are annotated with @NamedQuery or defined in an orm.xml file.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With