Search code examples
jpaopenjpa

Open JPA : An error occurred while parsing the query filter 'MY_QUERY' Error message: No field named "accessAuthorizationVs" in class "MyEntityClass"


I have configured it in my Rational Software Architect 8.0.4, by enabling the JPA 1.0 facet. It autogenerates almost all my entity classes except for the id's. So I manually add them. I am trying to query a simple table APP_USER that has one-to-many relation to ACCESS_AUTHORIZATION table. See below for the configurations and entity classes.

Relationship between my tables during the auto entity generation process

APP_USER Entity

enter image description here

When I try to execute a simple named query which is

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

It throws an exception

**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)

Here's a snapshot of my persistence.xml:

enter image description here

Can anyone guide me what I am doing wrong here? The field by that name is clearly defined in my entity class. Also I would like to mention that I had to enhance the classes[followed this] as there was an earlier error about classes not being enhanced.


Solution

  • When you create a named query in OpenJPA, remember that you are writing JPQL, not native SQL. The syntax is similar, but a little different.

    In this case, I suggest changing your named query to the following:

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

    This will return an object of the AppUserEntity class which will include the set of AccessAuthorizationV objects (lazy loaded by default).

    For more details, see the JPQL Language Reference.