JPA Entities named with dot notation

余生颓废 提交于 2019-12-12 03:35:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!