Using reserved JPQL keywords with JPA

后端 未结 2 931
礼貌的吻别
礼貌的吻别 2020-12-18 01:43

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

相关标签:
2条回答
  • 2020-12-18 02:10

    You don't have to rename the class - and you shouldn't - the name you have chosen reflects your domain in the best way, and you should not change it because of tool or framework limitations, in case the tool/framework provides a way to avoid the "clash". JPA provides such a way.

    0 讨论(0)
  • 2020-12-18 02:18

    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.

    0 讨论(0)
提交回复
热议问题