java.lang.IllegalStateException:试图对关闭的 EntityManagerFactory 执行操作
我有 Eclipse Indigo,用于使用 Glassfish 3 Open Source 开发 JSF 2 项目,这在我的计算机中,然后在我的 EC2 实例中,在 Amazon AWS 中,对于两个 Glassfish,我都创建了一个 JDBC 连接池以与我的JPA 实体管理器.
I have Eclipse Indigo that I use to develop a JSF 2 project using Glassfish 3 Open Source, this in my computer then in my EC2 instance too, in Amazon AWS, for both Glassfish's I created a JDBC Connection Pool to use with my JPA Entity Manager.
在本地,我的项目运行良好,但是当我部署该项目并尝试执行相同的表单时,该表单会从运行 GlassFIsh 的同一实例 EC2 中运行的数据库中获取一些值.
Locally my project works pretty fine, but when I deploy the project and try to execute the same form, which gets some values from the database that is running in the same instance EC2 that is running the GlassFIsh tough.
我收到这条消息:
服务器错误:类 javax.faces.el.EvaluationException
我正在搜索它,但到目前为止我没有找到任何东西.
I'm searching about it, but I don't found anything so far.
我应该为它做一些配置吗?
There's some configuration that I shoud do for it works ?
这是堆栈跟踪:
javax.faces.FacesException: #{reportc.generateReport}: javax.ejb.EJBException
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:636)
Caused by: javax.faces.el.EvaluationException: javax.ejb.EJBException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 32 more
Caused by: javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5193)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5091)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4879)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at $Proxy225.listLastMinutes(Unknown Source)
at com.brainset.eao.__EJB31_Generated__LogEAO__Intf____Bean__.listLastMinutes(Unknown Source)
at com.brainset.controller.ReportControl.getLog(ReportControl.java:234)
at com.brainset.controller.ReportControl.generateReport(ReportControl.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 33 more
Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManagerFactory.
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.verifyOpen(EntityManagerFactoryDelegate.java:305)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:276)
编辑 2:这就是我使用 EntityManager 的方式:
EDIT 2: This is how I'm using the EntityManager:
@Stateless(mappedName = "logEAO")
@LocalBean
public class LogEAO {
@PersistenceContext
private EntityManager em;
public LogEAO() {}
public Log find(int id) {
return em.find(Log.class, id);
}
// ..
推荐答案
来自您的堆栈跟踪:
Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManagerFactory.
Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManagerFactory.
您的 EJB 代码看起来不错.这更有可能是 Glassfish 错误或配置错误:
Your EJB code looks all right. This is more likely a Glassfish bug or misconfiguration:
- 确保您的 JTA 数据源配置正确
- 确保您'重新使用没有重新部署错误的 Glassfish 版本
- 此重新部署错误已在 3.1.2 和 4.0 中修复
这只能意味着您正在手动管理 EntityManagerFactory
(和 EntityManager
),而不是让容器仅通过 @ 来完成这项工作持久化上下文
.
This can only mean that you're manually managing the EntityManagerFactory
(and EntityManager
) instead of letting the container do the job by just @PersistenceContext
.
EntityManagerFactory
旨在仅在 webapp 启动时创建一次,在整个 webapp 生命周期中重复使用,并在 webapp 关闭时关闭.它不应该在某个地方中途关闭或被序列化并在下一个重启周期中重复使用.
The EntityManagerFactory
is intented to be created only once on webapp's startup, reused throughout the entire webapp's lifetime and closed on webapp's shutdown. It should not be closed somewhere halfway or be serialized and reused for a next restart cycle.
由于您显然是针对 Glassfish,我强烈建议您不要自己管理它,而是让 Glassfish 来完成这项工作.您最终会得到更简单的 EJB 代码,而无需手动管理事务.
Since you're apparently targeting Glassfish, I would strongly recommend to not manage it yourself, but letting Glassfish do the job. You end up with much simpler EJB code without all the hassle to manage transactions manually.
- 获取 EntityManagerFactory 的最佳做法莉>
相关文章