Thursday, June 14, 2012

org.apache.openjpa.persistence.ArgumentException: There is no query with the name "getEmpployeesData" defined for any of the known persistent classes

Exception while trying a add a new Persistent Entity.

I added a new table in the database for Employee records. Created a bean for the same with a named query as shown below.

 @Entity
@NamedQuery(name = "getEmployeeData", query = "select EmployeeEntity from EMPLOYEE  EmployeeEntity where EmployeeEntity.DEPT=:deptId")
@Table(name = "EMPLOYEE")
public class EmployeeEntity {

}
Code to invoke this query.

EntityManager em;
....
....
Query getEmployeeDataQuery = em.createNamedQuery("getEmployeeData");
getEmployeeDataQuery.setParameter("deptId", deptId);           
ArrayList<Employee> employeeList= getEmployeeDataQuery .getResultList();



While trying to invoke this query I am getting following exception : 



SEVERE: Exception Occured : EJB Exception: ; nested exception is:
        <openjpa-1.1.1-SNAPSHOT-r422266:1172209 fatal user error> org.apache.openjpa.persistence.ArgumentException: There is no query with the name "getEmpployeesData" defined for any of the known persistent classes: [com.test.EmployeeEntity,com.test.EmployeeEntity].; nested exception is: <openjpa-1.1.1-SNAPSHOT-r422266:1172209 fatal user error> org.apache.openjpa.persistence.ArgumentException: There is no query with the name "getEmpployeesData" defined for any of the known persistent classe
com.test.EmployeeEntity]
javax.ejb.EJBException: EJB Exception: ; nested exception is:
        <openjpa-1.1.1-SNAPSHOT-r422266:1172209 fatal user error> org.apache.openjpa.persistence.ArgumentException: There is no query with the name "getEmpployeesData" defined for any of the known persistent classes: [com.test.EmployeeEntity, com.test.EmployeeEntity].; nested exception is: <openjpa-1.1.1-SNAPSHOT-r422266:1172209 fatal user error> org.apache.openjpa.persistence.ArgumentException: There is no query with the name "getEmpployeesData" defined for any of the known persistent classe
s: [com.test.EmployeeEntity].
<openjpa-1.1.1-SNAPSHOT-r422266:1172209 fatal user error> org.apache.openjpa.persistence.ArgumentException: There is no query with the name "getEmpployeesData" defined for any of the known persistent classes: [com.test.EmployeeEntity]
        at org.apache.openjpa.meta.MetaDataRepository.getQueryMetaData(MetaDataRepository.java:1596)
        at org.apache.openjpa.persistence.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:895)
        at org.apache.openjpa.persistence.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:77)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at weblogic.deployment.BasePersistenceContextProxyImpl.invoke(BasePersistenceContextProxyImpl.java:111)
        at weblogic.deployment.TransactionalEntityManagerProxyImpl.invoke(TransactionalEntityManagerProxyImpl.java:78)
        at weblogic.deployment.BasePersistenceContextProxyImpl.invoke(BasePersistenceContextProxyImpl.java:92)
        at weblogic.deployment.TransactionalEntityManagerProxyImpl.invoke(TransactionalEntityManagerProxyImpl.java:18)
        at $Proxy178.createNamedQuery(Unknown Source)
        at services.EmployeeDataServiceBean.getEmpployeesData(EmployeeDataServiceBean.java:295)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
        at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
        at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
        at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
        at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
        at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at com.oracle.pitchfork.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:34)
        at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:54)
        at com.oracle.pitchfork.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:42)
        at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
        at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
        at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
        at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy183.getEmpployeesData(Unknown Source)
        at services.EmployeeDataService_4op81c_EmployeeDataServiceImpl.__WL_invoke(Unknown Source)
        at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:40)
        at services.EmployeeDataService_4op81c_EmployeeDataServiceImpl.getEmpployeesData(Unknown Source)
        at services.EmployeeDataService_4op81c_EmployeeDataServiceImpl_CBV.getEmpployeesData(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:85)
        at $Proxy179.getEmpployeesData(Unknown Source)



Solution to the problem :

I forgot to add the persistent entity in my persistence.xml file. It resolved the issue,

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit transaction-type="JTA" name="TestDataService">
        <jta-data-source>TestDataService</jta-data-source>       
        <class>com.test.DeptEntity</class>
        <class>com.test.EmployeeEntity</class>
        <properties>
            <property name="showSql" value="true"/>
            <property name="formatSql" value="true"/>
        </properties>
    </persistence-unit>
</persistence>

4 comments:

  1. Following are the other exceptions which might occur:

    Caused by: org.apache.openjpa.persistence.ArgumentException: An error occurred while parsing the query filter "select EmployeeEntity from EMPLOYEE EmployeeEntity where EmployeeEntity.DEPTID=:deptId".
    Error message: The name "EMPLOYEE" is not a recognized entity or identifier. Perhaps you meant EmployeeEntity, which is a close match. Known entity names: [EmployeeEntity, DeptEntity]
    at org.apache.openjpa.kernel.exps.AbstractExpressionBuilder.parseException(AbstractExpressionBuilder.java:118)
    at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getClassMetaData(JPQLExpressionBuilder.java:177)
    at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.resolveClassMetaData(JPQLExpressionBuilder.java:150)
    at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaData(JPQLExpressionBuilder.java:225)
    at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaData(JPQLExpressionBuilder.java:195)
    at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateType(JPQLExpressionBuilder.java:188)
    at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.access$600(JPQLExpressionBuilder.java:69)
    at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder$ParsedJPQL.populate(JPQLExpressionBuilder.java:1754)
    at org.apache.openjpa.kernel.jpql.JPQLParser.populate(JPQLParser.java:56)
    at org.apache.openjpa.kernel.ExpressionStoreQuery.populateFromCompilation(ExpressionStoreQuery.java:153)
    at org.apache.openjpa.kernel.QueryImpl.newCompilation(QueryImpl.java:657)
    at org.apache.openjpa.kernel.QueryImpl.compilationFromCache(QueryImpl.java:638)
    at org.apache.openjpa.kernel.QueryImpl.compileForCompilation(QueryImpl.java:604)
    at org.apache.openjpa.kernel.QueryImpl.compileForExecutor(QueryImpl.java:666)
    at org.apache.openjpa.kernel.QueryImpl.compile(QueryImpl.java:573)
    at kodo.kernel.KodoQuery.compile(KodoQuery.java:75)


    Resolution was to fix the query:


    "select EmployeeEntity from EMPLOYEE EmployeeEntity where EmployeeEntity.DEPTID=:deptId".

    The above query has the actual Oracle table name, instead it should have EJB name, and the EJB fields should be used for column names.


    "select employeeEntity from EmployeeEntity employeeEntity where employeeEntity.deptId=:deptId".

    ReplyDelete
  2. did you mean to say "Entity name" instead of "EJB name"?

    ReplyDelete
    Replies
    1. yes Matthew, I meant the Entity Name only.

      Delete
    2. Hi my query is using entity name but still getting the same error.. this entity is not part of persistence.xml file, any solution for this please?

      Delete