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>