JPA NamedQuery不在Glassfish4中(但在Glassfish3中有效)

时间:2018-05-01 20:15:28

标签: java oracle jpa glassfish eclipselink

我正在使用带有JPA(EclipseLink)的EJB从Glassfish3迁移到Glassfish4的应用程序。大部分都在使用新服务器,但由于某种原因,这个命名查询(在JPQL语句中实例化对象)不起作用:

@NamedQuery(
    name = "countByUserType", 
    query = "SELECT new org.util.CountBean(ev.user.type, count(ev.user.id)) 
             FROM Event ev WHERE ev.idTs = :idTs GROUP BY ev.user.type"
)

我的类CountBean是一个简单的POJO类

public class CountBean{
    String label;
    Long count;
    public CountBean(String label, Long count) {
        this.label = label;
        this.count = count;
    }
}

我得到的错误信息如下:

 Caused by: Exception [EclipseLink-6168] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.QueryException
 Exception Description: Query failed to prepare, unexpected error occurred: [java.lang.NullPointerException].
 Internal Exception: java.lang.NullPointerException
 Query: ReportQuery(name="countByUserType" referenceClass=Event jpql="SELECT new org.util.CountBean(ev.user.type, count(ev.user.idU), 0l) FROM Event ev WHERE ev.idTs = :idTs GROUP BY ev.user.type")
    at org.eclipse.persistence.exceptions.QueryException.prepareFailed(QueryException.java:1584)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:680)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:888)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:613)
    at org.eclipse.persistence.internal.jpa.QueryImpl.getDatabaseQueryInternal(QueryImpl.java:341)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1107)
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:522)
    at org.un.sers.repository.EventFacade.countRoomsBooked(EventFacade.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4695)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:630)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
    at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46)
    at sun.reflect.GeneratedMethodAccessor90.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
    at sun.reflect.GeneratedMethodAccessor91.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4667)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4655)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
    ... 35 more
 Caused by: java.lang.NullPointerException
    at org.eclipse.persistence.queries.ConstructorReportItem.initialize(ConstructorReportItem.java:167)
    at org.eclipse.persistence.queries.ReportQuery.prepare(ReportQuery.java:1058)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:661)
    ... 69 more

我很高兴能从遇到类似问题的人那里得到一些见解,或者我发布的代码中似乎有些东西。同样,这在我在Glassfish 3上部署应用程序时有效,但在Glassfish 4上没有,并且它连接的数据库是Oracle 11g。

1 个答案:

答案 0 :(得分:2)

旧版eclipselink中的

这是错误,请查看:

<强>解决方案

更好的解决方法是升级到最新版本2.7.1 Latest Release

我希望使用Payara Server代替GlassFish 4 Server ,修复了很多错误我对这台服务器有很好的体验,它性能更高,速度更快GlassFish现在。

相关问题