由IllegalStateException引起的Hibernate InstantiationException:此Web容器尚未启动

时间:2015-06-14 15:20:47

标签: java hibernate

我正在开发一个用于个人财务监控的Web应用程序。从EclipseLink切换到Hibernate后,我遇到了以下异常。当应用程序尝试通过CashFlowDaoImpl.findByUser(String username)从数据库获取当前用户的现金流列表时,会发生异常。

为什么会发生此异常?我该怎么做才能阻止它?

org.hibernate.InstantiationException: Could not instantiate entity:  : com.singularityfx.cashelyok.entities.CashFlow
            at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
            at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
            at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
            at javax.faces.component.UIData.getValue(UIData.java:732)
            at javax.faces.component.UIData.getDataModel(UIData.java:1811)
            at javax.faces.component.UIData.setRowIndexWithoutRowStatePreserved(UIData.java:484)
            at javax.faces.component.UIData.setRowIndex(UIData.java:473)
            at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:82)
            at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:869)
            at javax.faces.component.UIData.encodeBegin(UIData.java:1133)
            at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1854)
            at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
            at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
            at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
            at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
            at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
            at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
            at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
            at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
            at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
            at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
            at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
            at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
            at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
            at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:253)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
            at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
            at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
            at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
            at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
            at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
            at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
            at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
            at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
            at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
            at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
            at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
            at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
            at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
            at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
            at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
            at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.ELException: javax.persistence.PersistenceException: org.hibernate.InstantiationException: Could not instantiate entity:  : com.singularityfx.cashelyok.entities.CashFlow
            at javax.el.BeanELResolver.getValue(BeanELResolver.java:368)
            at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
            at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
            at com.sun.el.parser.AstValue.getValue(AstValue.java:140)
            at com.sun.el.parser.AstValue.getValue(AstValue.java:204)
            at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
            at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
            at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
            at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
            ... 54 more
Caused by: javax.persistence.PersistenceException: org.hibernate.InstantiationException: Could not instantiate entity:  : com.singularityfx.cashelyok.entities.CashFlow
            at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
            at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
            at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:458)
            at com.sun.enterprise.container.common.impl.QueryWrapper.getResultList(QueryWrapper.java:84)
            at com.sun.enterprise.container.common.impl.TypedQueryWrapper.getResultList(TypedQueryWrapper.java:73)
            at com.singularityfx.cashelyok.entities.dao.CashFlowDaoImpl.findByUser(CashFlowDaoImpl.java:73)
            at com.singularityfx.cashelyok.managedbeans.CashFlowMBean.updateCashFlows(CashFlowMBean.java:48)
            at com.singularityfx.cashelyok.managedbeans.CashFlowMBean.init(CashFlowMBean.java:44)
            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:483)
            at org.jboss.weld.interceptor.proxy.SimpleMethodInvocation.invoke(SimpleMethodInvocation.java:32)
            at org.jboss.weld.interceptor.chain.AbstractInterceptionChain.invokeNext(AbstractInterceptionChain.java:95)
            at org.jboss.weld.interceptor.chain.AbstractInterceptionChain.invokeNextInterceptor(AbstractInterceptionChain.java:78)
            at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:48)
            at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:33)
            at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:55)
            at com.singularityfx.cashelyok.managedbeans.CashFlowMBean$Proxy$_$$_WeldSubclass.lifecycle_mixin_$$_postConstruct(Unknown Source)
            at org.jboss.weld.interceptor.util.InterceptionUtils.executePostConstruct(InterceptionUtils.java:35)
            at org.jboss.weld.interceptor.util.InterceptionUtils.executePostConstruct(InterceptionUtils.java:47)
            at org.jboss.weld.injection.producer.BeanInjectionTarget.postConstruct(BeanInjectionTarget.java:63)
            at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:161)
            at org.jboss.weld.context.ForwardingContextual.create(ForwardingContextual.java:27)
            at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
            at org.jboss.weld.context.PassivatingContextWrapper$AbstractPassivatingContextWrapper.get(PassivatingContextWrapper.java:64)
            at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:93)
            at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
            at com.singularityfx.cashelyok.managedbeans.CashFlowMBean$Proxy$_$$_WeldClientProxy.getCashFlows(Unknown Source)
            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:483)
            at javax.el.BeanELResolver.getValue(BeanELResolver.java:363)
            ... 62 more
Caused by: org.hibernate.InstantiationException: Could not instantiate entity:  : com.singularityfx.cashelyok.entities.CashFlow
            at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:127)
            at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:136)
            at org.hibernate.tuple.entity.AbstractEntityTuplizer.instantiate(AbstractEntityTuplizer.java:737)
            at org.hibernate.persister.entity.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:4761)
            at org.hibernate.internal.SessionImpl.instantiate(SessionImpl.java:1427)
            at org.hibernate.internal.SessionImpl.instantiate(SessionImpl.java:1415)
            at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1619)
            at org.hibernate.loader.Loader.getRow(Loader.java:1515)
            at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:726)
            at org.hibernate.loader.Loader.processResultSet(Loader.java:953)
            at org.hibernate.loader.Loader.doQuery(Loader.java:921)
            at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
            at org.hibernate.loader.Loader.doList(Loader.java:2554)
            at org.hibernate.loader.Loader.doList(Loader.java:2540)
            at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
            at org.hibernate.loader.Loader.list(Loader.java:2365)
            at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497)
            at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
            at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
            at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300)
            at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
            at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
            at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449)
            ... 93 more
Caused by: java.lang.IllegalStateException: This web container has not yet been started
            at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1652)
            at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1611)
            at sun.misc.Unsafe.defineClass(Native Method)
            at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:63)
            at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:399)
            at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:394)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:393)
            at sun.reflect.MethodAccessorGenerator.generateConstructor(MethodAccessorGenerator.java:92)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:55)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
            at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:124)
            ... 115 more

Servlet.service() for servlet facesServlet threw exception
java.lang.IllegalStateException: This web container has not yet been started
            at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1652)
            at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1611)
            at sun.misc.Unsafe.defineClass(Native Method)
            at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:63)
            at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:399)
            at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:394)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:393)
            at sun.reflect.MethodAccessorGenerator.generateConstructor(MethodAccessorGenerator.java:92)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:55)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
            at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:124)
            at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:136)
            at org.hibernate.tuple.entity.AbstractEntityTuplizer.instantiate(AbstractEntityTuplizer.java:737)
            at org.hibernate.persister.entity.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:4761)
            at org.hibernate.internal.SessionImpl.instantiate(SessionImpl.java:1427)
            at org.hibernate.internal.SessionImpl.instantiate(SessionImpl.java:1415)
            at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1619)
            at org.hibernate.loader.Loader.getRow(Loader.java:1515)
            at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:726)
            at org.hibernate.loader.Loader.processResultSet(Loader.java:953)
            at org.hibernate.loader.Loader.doQuery(Loader.java:921)
            at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
            at org.hibernate.loader.Loader.doList(Loader.java:2554)
            at org.hibernate.loader.Loader.doList(Loader.java:2540)
            at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
            at org.hibernate.loader.Loader.list(Loader.java:2365)
            at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497)
            at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
            at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
            at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300)
            at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
            at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
            at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449)
            at com.sun.enterprise.container.common.impl.QueryWrapper.getResultList(QueryWrapper.java:84)
            at com.sun.enterprise.container.common.impl.TypedQueryWrapper.getResultList(TypedQueryWrapper.java:73)
            at com.singularityfx.cashelyok.entities.dao.CashFlowDaoImpl.findByUser(CashFlowDaoImpl.java:73)
            at com.singularityfx.cashelyok.managedbeans.CashFlowMBean.updateCashFlows(CashFlowMBean.java:48)
            at com.singularityfx.cashelyok.managedbeans.CashFlowMBean.init(CashFlowMBean.java:44)
            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:483)
            at org.jboss.weld.interceptor.proxy.SimpleMethodInvocation.invoke(SimpleMethodInvocation.java:32)
            at org.jboss.weld.interceptor.chain.AbstractInterceptionChain.invokeNext(AbstractInterceptionChain.java:95)
            at org.jboss.weld.interceptor.chain.AbstractInterceptionChain.invokeNextInterceptor(AbstractInterceptionChain.java:78)
            at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:48)
            at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:33)
            at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:55)
            at com.singularityfx.cashelyok.managedbeans.CashFlowMBean$Proxy$_$$_WeldSubclass.lifecycle_mixin_$$_postConstruct(Unknown Source)
            at org.jboss.weld.interceptor.util.InterceptionUtils.executePostConstruct(InterceptionUtils.java:35)
            at org.jboss.weld.interceptor.util.InterceptionUtils.executePostConstruct(InterceptionUtils.java:47)
            at org.jboss.weld.injection.producer.BeanInjectionTarget.postConstruct(BeanInjectionTarget.java:63)
            at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:161)
            at org.jboss.weld.context.ForwardingContextual.create(ForwardingContextual.java:27)
            at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
            at org.jboss.weld.context.PassivatingContextWrapper$AbstractPassivatingContextWrapper.get(PassivatingContextWrapper.java:64)
            at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:93)
            at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
            at com.singularityfx.cashelyok.managedbeans.CashFlowMBean$Proxy$_$$_WeldClientProxy.getCashFlows(Unknown Source)
            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:483)
            at javax.el.BeanELResolver.getValue(BeanELResolver.java:363)
            at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
            at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
            at com.sun.el.parser.AstValue.getValue(AstValue.java:140)
            at com.sun.el.parser.AstValue.getValue(AstValue.java:204)
            at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
            at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
            at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
            at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
            at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
            at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
            at javax.faces.component.UIData.getValue(UIData.java:732)
            at javax.faces.component.UIData.getDataModel(UIData.java:1811)
            at javax.faces.component.UIData.setRowIndexWithoutRowStatePreserved(UIData.java:484)
            at javax.faces.component.UIData.setRowIndex(UIData.java:473)
            at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:82)
            at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:869)
            at javax.faces.component.UIData.encodeBegin(UIData.java:1133)
            at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1854)
            at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
            at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
            at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
            at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
            at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
            at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
            at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
            at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
            at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
            at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
            at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
            at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
            at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
            at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:253)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
            at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
            at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
            at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
            at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
            at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
            at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
            at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
            at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
            at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
            at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
            at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
            at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
            at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
            at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
            at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
            at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
            at java.lang.Thread.run(Thread.java:745)
]]

现金流

@Entity
public class CashFlow implements Comparable<CashFlow> {
    @Id
    @GeneratedValue
    private int id;
    @NotNull @Min(0)
    private double amount;
    @Size(max=200)
    private String description;
    @NotNull
    private LocalDate date;
    @OneToOne @NotNull
    @JoinColumns({
        @JoinColumn(name="NAME", referencedColumnName="NAME"),
        @JoinColumn(name="USERNAME", referencedColumnName="USERNAME")
    })
    private CashFlowCategory category;
    @Transient
    private boolean editable = false;

    public CashFlow() {}

    public CashFlow(LocalDate date,
            CashFlowCategory category,
            String description,
            double amount) {
        this.date = date;
        this.category = category;
        this.description = description;
        this.amount = amount;
    }

    @Column(name="username")
    public String getUsername() {
        return category.getPrimaryKey().getUsername();
    }

    // getters, setters, hashCode(), equals(), compareTo(), etc.
}

CashFlowDaoImpl

public class CashFlowDaoImpl extends DaoImpl<CashFlow, String>
                             implements CashFlowDao {

    @Override
    public List<CashFlow> findByUser(String username) {
        String qlString =
            "SELECT cf "
            + "FROM CashFlow cf "
            + "INNER JOIN cf.category cat "
            + "WHERE cat.primaryKey.username = '" + username + "'";
        TypedQuery<CashFlow> query = entityManager.createQuery(qlString, CashFlow.class);
        List<CashFlow> result = query.getResultList();
        Collections.<CashFlow>sort(result);
        return result;
    }

    // ....
}

的persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="cashelyok" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>cashelyok-resource</jta-data-source>
        <properties>
            <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" />
            <property name="hibernate.hbm2ddl.auto" value="validate" />
            </properties>
    </persistence-unit>
</persistence>

1 个答案:

答案 0 :(得分:3)

The problem can be solved by adding the following property to persistence.xml:

<property name="hibernate.classloading.use_current_tccl_as_parent" value="false" />