![](/img/trans.png)
[英]Servlet works on my Tomcat server, but not my Glassfish4 server
[英]JPA NamedQuery not in Glassfish4 (but works in Glassfish3)
我正在将使用带有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时,此方法也有效。
这是旧版本的eclipselink中的错误 ,请检查以下内容:
解
解决该问题的更好方法是升级到最新版本2.7.1 最新版本
除了要使用Payara Server代替GlassFish 4 Server之外 ,还修复了许多错误,因为我对这台服务器有很好的经验,它现在的性能和性能比GlassFish更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.