I have two Entities which have the same class name but reside in different packages, only one of them is mentioned in the persistence.xml.
I a NamedQuery I use the unqualified class name of one of these entities. If I execute that query I get an exception;
Caused by: com.objectdb.o.InternalException: Unexpected internal exception at com.objectdb.o.JPE.h(JPE.java:163) at com.objectdb.o.ERR.f(ERR.java:68) at com.objectdb.o.OBC.onObjectDBError(OBC.java:1456) at com.objectdb.jpa.JpaQuery.getSingleResult(JpaQuery.java:664) at objdbTest.Singleton.findItem(Singleton.java:62) at objdbTest.SLSBObjDb.findItem(SLSBObjDb.java:42) 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 org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052) at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124) at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5367) at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619) at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801) at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571) at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162) at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144) 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.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:862) at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801) at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:371) at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5339) at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5327) at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:206) ... 40 more Caused by: java.lang.NullPointerException at com.objectdb.o.MST.aY(MST.java:866) at com.objectdb.o.MST.aX(MST.java:848) at com.objectdb.o.MST.aW(MST.java:809) at com.objectdb.o.MST.aU(MST.java:724) at com.objectdb.o.BQI.Ut(BQI.java:123) at com.objectdb.o.PRG.ab(PRG.java:601) at com.objectdb.o.QRM.US(QRM.java:259) at com.objectdb.o.MST.US(MST.java:888) at com.objectdb.o.WRA.US(WRA.java:286) at com.objectdb.o.WSM.US(WSM.java:113) at com.objectdb.o.QRR.g(QRR.java:225) at com.objectdb.o.QRR.b(QRR.java:144) at com.objectdb.jpa.JpaQuery.getSingleResult(JpaQuery.java:657) ... 64 more
Here is the class doing the query on objdbTest.Item
package objdbTest; import .... @Entity @NamedQueries({ @NamedQuery(name = "objdbTest.Singleton.getItem", query = "SELECT o FROM Item o WHERE o.cachedKey = :cachedKey"), @NamedQuery(name = "objdbTest.Singleton.count", query = "SELECT COUNT(x) FROM Item x") }) public class Singleton implements Serializable { public static Singleton getInstance(EntityManager em) { Singleton c = em.find(Singleton.class, "1"); if (c == null) { c = new Singleton(); em.persist(c); } return c; } @Id protected String id = "1"; @SuppressWarnings("unused") // used by JPA @Version private int version; @Basic protected java.lang.Integer lastInstance; public void generateItems(EntityManager em, int howMany) { if (lastInstance == null) { lastInstance = 0; } int endCnt = lastInstance + howMany; int startCnt = lastInstance; while (endCnt > startCnt) { startCnt++; Item item = new Item(this, startCnt); em.persist(item); lastInstance = startCnt; } } public Item findItem(EntityManager em, int which) { TypedQuery<Item> q = em.createNamedQuery("objdbTest.Singleton.getItem", Item.class); q.setParameter("cachedKey", Integer.toString(which)); try { return q.getSingleResult(); } catch (NoResultException e) { return null; } } public long howManyItemsExist(EntityManager em) { TypedQuery<Long> q = em.createNamedQuery("objdbTest.Singleton.count", Long.class); q.setFlushMode(FlushModeType.AUTO); try { return q.getSingleResult(); } catch (javax.persistence.NoResultException ex) { return -1; } } private static final long serialVersionUID = 2215109025397291357L; }
If I change the query to
@NamedQuery(name = "objdbTest.Singleton.count", query = "SELECT COUNT(x) FROM objdbTest.Item x")
everything works fine.
The persistence.xml is
<persistence-unit name="Experiment8objPU" transaction-type="JTA"> <provider>com.objectdb.jpa.Provider</provider> <class>objdbTest.Singleton</class> <class>objdbTest.Item</class> <properties> <property name="javax.persistence.jdbc.url" value="C:/development/ObjectDb/objectdb-2.2.9_04/db/ObjectTestApp.odb"/> <property name="javax.persistence.jdbc.user" value="admin"/> <property name="javax.persistence.jdbc.password" value="admin"/> </properties> </persistence-unit>
The notes on my previous thread described the attached projects