打开JPA:解析查询过滤器'MY_QUERY'时发生错误错误消息:类“MyEntityClass”中没有名为“accessAuthorizationVs”的字段

时间:2012-10-29 17:24:13

标签: jpa openjpa

我在Rational Software Architect 8.0.4中通过启用JPA 1.0方面对其进行了配置。除了id之外,它几乎自动生成我的所有实体类。所以我手动添加它们。我正在尝试查询与ACCESS_AUTHORIZATION表具有一对多关系的简单表APP_USER。请参阅下面的配置和实体类。

Relationship between my tables during the auto entity generation process

APP_USER Entity

enter image description here

当我尝试执行一个简单的命名查询

SELECT a.accessAuthorizationVs, a.empName, a.userCnum FROM AppUserEntity a WHERE a.userCnum = :userCnum

抛出异常

**org.apache.openjpa.persistence.ArgumentException: An error occurred while parsing the query filter "SELECT a.accessAuthorizationVs, a.empName, a.userCnum FROM AppUserEntity a WHERE a.userCnum = :userCnum". Error message: No field named "accessAuthorizationVs" in class "class com.xxx.xxx.xxx.services.integration.entity.AppUserEntity".**
    at org.apache.openjpa.kernel.exps.AbstractExpressionBuilder.parseException(AbstractExpressionBuilder.java:118)
    at org.apache.openjpa.kernel.exps.AbstractExpressionBuilder.traversePath(AbstractExpressionBuilder.java:284)
    at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getPath(JPQLExpressionBuilder.java:1382)
    at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getPathOrConstant(JPQLExpressionBuilder.java:1337)

这是我的persistence.xml的快照:

enter image description here

任何人都可以指导我在这里做错了吗?该名称的字段在我的实体类中明确定义。另外我想提一下,我必须增强类[跟随this] ,因为之前有关于没有增强的类的错误。

1 个答案:

答案 0 :(得分:1)

在OpenJPA中创建命名查询时,请记住您正在编写JPQL而不是本机SQL。语法类似,但有点不同。

在这种情况下,我建议将您的命名查询更改为以下内容:

SELECT a FROM AppUserEntity a WHERE a.userCnum = :userCnum

这将返回AppUserEntity类的一个对象,该对象将包含一组AccessAuthorizationV对象(lazy loaded by default)。

有关详细信息,请参阅JPQL Language Reference