Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
411 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...