当我们在使用GlassFish 4.1构建的J2EE应用程序中按下按钮时,JSF 2和JPA2在EJB层中调用@ApplicationScoped
bean,堆栈跟踪显示为Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null
。其他调用看起来很好,它在这个特定的情况/按钮中发生了跟踪。
如果在post构造中执行对实体管理器的调用,则堆栈跟踪不会发生。
@PostConstruct
public void init() {
entityManager.getCriteriaBuilder();
}
以下是完整的堆栈跟踪:
警告:#{createWorkOrderBean.initFieldsFromComplementingDataSearchResult}:java.lang.IllegalStateException:无法检索unitName的EntityManagerFactory null javax.faces.FacesException:#{createWorkOrderBean.initFieldsFromComplementingDataSearchResult}:java.lang.IllegalStateException:无法为unitName null检索EntityManagerFactory at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) 在javax.faces.component.UICommand.broadcast(UICommand.java:315) 在javax.faces.component.UIData.broadcast(UIData.java:1108) 在javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790) 在javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) 在com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 在com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) 在javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) 在org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) 在org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:295) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) 在org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) 在org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) 在com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) 在org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282) at com.sun.enterprise.v3.services.impl.ContainerMapper $ HttpHandlerCallable.call(ContainerMapper.java:459) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) 在org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201) 在org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175) 在org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) 在org.glassfish.grizzly.filterchain.ExecutorResolver $ 9.execute(ExecutorResolver.java:119) 在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284) 在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201) 在org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133) 在org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) 在org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) 在org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561) 在org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) 在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) 在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access $ 100(WorkerThreadIOStrategy.java:56) 在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy $ WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) 在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:565) 在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:545) 在java.lang.Thread.run(Thread.java:748) 引发者:javax.faces.el.EvaluationException:java.lang.IllegalStateException:无法为unitName null检索EntityManagerFactory at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) ......还有41个 引起:java.lang.IllegalStateException:无法检索unitName null的EntityManagerFactory at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:138) 在com.sun.enterprise.container.common.impl.EntityManagerWrapper。 getDelegate(EntityManagerWrapper.java:171) 在com.sun.enterprise.container.common.impl.EntityManagerWrapper.getCriteriaBuilder(EntityManagerWrapper.java:834) at se.evado.server.ao.customer.kalmarenergi.KalmarEnergiElnatServerBusinessLogic $ TrimbleNisComplementer.copyComplementingDataToWorkOrder(KalmarEnergiElnatServerBusinessLogic.java:310) at se.evado.server.ao.web.bean.SearchComplementingDataBean.initWorkOrderFields(SearchComplementingDataBean.java:153) at se.evado.server.ao.web.bean.SearchComplementingDataBean $ Proxy $ $$ _ WeldClientProxy.initWorkOrderFields(Unknown Source) at se.evado.server.ao.web.bean.CreateWorkOrderBean.initFieldsFromComplementingDataSearchResult(CreateWorkOrderBean.java:337) 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:498) 在com.sun.el.parser.AstValue.invoke(AstValue.java:289) at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304) 在org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40) 在org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) 在javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) ......还有42个
为什么会发生这种情况?如何摆脱它?
答案 0 :(得分:0)
您必须为EntityManager命名。 首先,您必须在META-INF中放置一个persistance.xml,并为您的持久单元指定一个名称。
<script>
$("input[name='gender']").change(function(){
$('html, body').animate({
scrollTop: $("#profiel").offset().top
}, 2000);
});
</script>
之后你必须像这样注入EntityManager。
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="myUnit" transaction-type="JTA" />
</persistence>
这应该可以解决你的问题。