以点表示法命名的JPA实体 [英] JPA Entities named with dot notation

查看:97
本文介绍了以点表示法命名的JPA实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些JPA实体类,其中的实体名称包含一个点:

I have some JPA Entity classes in which the name of the entity contains a dot:

似乎这种命名方案导致命名查询出现问题.在下面的查询中,eclipse将为每个FROM子句以及对该实体的任何引用显示一个错误.如果我将实体名称更改为"City",所有这些错误都会消失.应该注意的是,jpa/hibernate似乎并没有对此提出质疑,因为它可以编译并可以正常工作.但是我想弄清楚如何保持这种命名方案,而Eclipse不会到处都有错误.

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") })

推荐答案

JPA规范暗示实体名称必须是Java标识符(不允许在字符串中使用句点/点字符). Eclipse Dali使用的默认JPQL解析器符合JPA规范.如果Hibernate扩展了规范,那么您也许可以使用JBoss Tools Dali扩展,并查看它是否提供了不同的解析器.

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.

或者,您可以在Eclipse首选项中禁用Dali的JPQL验证:

Alternatively, you could disable Dali's JPQL validation in the Eclipse preferences:

Java持久性> JPA>错误/警告>查询和生成器>无效或不完整的JPQL查询:忽略

Java Persistence > JPA > Errors/Warnings > Queries and generators > Invalid or incomplete JPQL queries: Ignore

这篇关于以点表示法命名的JPA实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆