问题
I have some JPA Entity classes in which the name of the entity contains a dot:
It seems this naming scheme is causing problems with named queries. In the queries below, eclipse displays an error for each FROM clause, and any references to the entity. If I change the name of the entity to just "City", all of these errors disappear. It should be noted that jpa/hibernate doesn't seem to actually take issue with it, as it compiles and works just fine. But I would like to figure out how to keep this naming scheme without Eclipse having errors everywhere.
@Entity (name = "gnf.City")
@Table (name = "CITY")
@NamedQueries ({ @NamedQuery (name = "City.getMaxId", query = "SELECT MAX (o.id) FROM gnf.City o"),
@NamedQuery (name = "City.getByCode", query = "SELECT c FROM gnf.City c WHERE c.code=:code"),
@NamedQuery (name = "City.getByNameAndState", query = "SELECT c FROM gnf.City c WHERE c.name=:name AND c.state=:state"),
@NamedQuery (name = "City.getByCodeAndState", query = "SELECT c FROM gnf.City c WHERE c.code=:code AND c.state=:state") })
回答1:
The JPA spec implies the Entity name must be a Java identifier (which does not allow a period/dot character in the string). The default JPQL parser used by Eclipse Dali adheres to the JPA spec. If Hibernate extends the spec, then you might be able to use the JBoss Tools Dali extension and see whether it supplies a different parser.
Alternatively, you could disable Dali's JPQL validation in the Eclipse preferences:
Java Persistence > JPA > Errors/Warnings > Queries and generators > Invalid or incomplete JPQL queries: Ignore
来源:https://stackoverflow.com/questions/37057025/jpa-entities-named-with-dot-notation