打开同一Web应用程序的新选项卡时,@ Stateless EJB发生冲突

时间:2015-04-15 06:06:02

标签: hibernate java-ee jpa-2.0 ejb-3.1

我创建了一个通用的@stateless EJB(LoadEntityEJBImpl),用于我的所有JPA事务。 我使用ejb-jar.xml注入没有注释的entityManager,以便我可以控制每个应用程序使用哪个持久性资源。

我遇到的问题是,在我的所有Web应用程序中,当我在页面上调用一个事务然后打开一个新选项卡到另一个页面时,我使用了这个EJB EJB有时会发生冲突并引发异常。

我认为可能发生的事情是当我点击第一页时创建EJB(如果不存在或者没有可用) 然后,当它完成使用时,它将返回EJB池(可用于其他请求)。 然后我打开我的新选项卡,将EJB从EJB池中拉出,并为其设置先前的参数。

returnedToPark是我的订单实体中的一列,但我没有以任何形式或形式选择此表,包括懒惰和egar加载。

例外如下:

java.lang.IllegalArgumentException: Unable to resolve attribute [returnedToPark] against path
 at org.hibernate.ejb.criteria.path.AbstractPathImpl.unknownAttribute(AbstractPathImpl.java:120)
 at org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:229)
 at org.hibernate.ejb.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:200)
 at au.com.xxx.ejb.LoadEntityEJBImpl.generateFilterPredicates(LoadEntityEJBImpl.java:317)
 at au.com.xxx.ejb.LoadEntityEJBImpl.generateFilterPredicatesWithDates(LoadEntityEJBImpl.java:157)
 at au.com.xxx.ejb.LoadEntityEJBImpl.createCriteriaQuery(LoadEntityEJBImpl.java:123)
 at au.com.xxx.ejb.LoadEntityEJBImpl.buildEntityObjectsQuery(LoadEntityEJBImpl.java:110)
 at au.com.xxx.ejb.LoadEntityEJBImpl.getEntityObjectsByRange(LoadEntityEJBImpl.java:806)
 at sun.reflect.GeneratedMethodAccessor184.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:182)
 at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:164)
 at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:180)
 at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:99)
 at sun.reflect.GeneratedMethodAccessor144.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:182)
 at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:164)
 at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:80)
 at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:212)
 at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:181)
 at org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:268)
 at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:263)
 at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:86)
 at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:303)
 at com.sun.proxy.$Proxy98.getEntityObjectsByRange(Unknown Source)
 at org.apache.jsp.operations.container.schedule.containerScheduleIndex_jsp._jspService(containerScheduleIndex_jsp.java:1584)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
 at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:611)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 at java.lang.Thread.run(Thread.java:745) 

以下是ejb-jar.xml的内容:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
    version="3.1">
    <module-name>PKWebapp</module-name>
    <enterprise-beans>
        <session id="PKWebappID">
            <ejb-name>LoadEntityEJBPKWebapp</ejb-name>
            <mapped-name>LoadEntityEJBPKWebappMapped</mapped-name>
            <business-remote>au.com.xxx.ejb.LoadEntityEJB</business-remote>
            <ejb-class>au.com.xxx.ejb.LoadEntityEJBImpl</ejb-class>
            <session-type>Stateless</session-type>
            <persistence-context-ref id="PKIDWebapp">
                <description>PKWebapp reference</description>
                <persistence-context-ref-name>LoadEntityEJBImplRefNamePKWebapp/entityManager</persistence-context-ref-name>
                <persistence-unit-name>PKWebappDS</persistence-unit-name>
                <persistence-context-type>Transaction</persistence-context-type>
                <injection-target>
                    <injection-target-class>au.com.xxx.ejb.LoadEntityEJBImpl</injection-target-class>
                    <injection-target-name>entityManager</injection-target-name>
                </injection-target>
            </persistence-context-ref>
        </session>
    </enterprise-beans>
</ejb-jar>

由于隐私,我无法提供LoadEntityEJBImpl的完整代码示例,但我可以提供一些小样本。

@Stateless
public class LoadEntityEJBImpl<T> implements LoadEntityEJB<T>, Serializable {
    private static final long serialVersionUID = -6359834805546452108L;
    private static final Logger log = Logger.getLogger(LoadEntityEJBImpl.class.getName());
    private EntityManagerFactory factory;
    private EntityManager entityManager;
    private Class<T> entityClass;
    @Resource
    private EJBContext context;

@Override
public EntityManager getEM() {
if (entityManager == null) {
    entityManager = getFactory().createEntityManager();
}
return entityManager;
}


@Override
public EntityManagerFactory getFactory() {
return factory;
}

public void setFactory(EntityManagerFactory factory) {
this.factory = factory;
}
...

提前感谢您提供的任何帮助。

1 个答案:

答案 0 :(得分:0)

在堆栈跟踪中,我看到一些容器调度程序(在org.apache.jsp.operations.container.schedule.containerScheduleIndex_jsp._jspService(containerScheduleIndex_jsp.java:1584))运行方法getEntityObjectsByRange(在com.sun.proxy。 $ Proxy98.getEntityObjectsByRange(未知来源))。检查glassfish中的部署,并从中清除可能的旧部署。