本文介绍了持久性事务类型值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于persistence.xml配置参数transaction-type的问题。如果将此参数设置为值RESOURCE_LOCAL,则应用程序将在tomcat应用程序服务器中正常运行。但不是在玻璃鱼。 Glassfish给了我下一个错误:
持久性上下文引用名称[com.test.webtest.persistence.dao.jpa模块[webFrontend-1.0-SNAPSHOT]中的.AbstractGenericDaoJpa / entityManager]解析为名为[basicPersistenceUnit]的持久性单元,其类型为RESOURCE_LOCAL。只有事务类型为JTA的持久性单元可以用作容器管理实体管理器。请验证您的申请。
了java.lang.RuntimeException:在模块的持久性的上下文参考名[com.test.webtest.persistence.dao.jpa.AbstractGenericDaoJpa / EntityManager的] [webFrontend-1.0-快照]解析为称为持久性单元[basicPersistenceUnit],其类型为RESOURCE_LOCAL。只有事务类型为JTA的持久性单元可以用作容器管理实体管理器。请验证您的申请。
当我将参数更改为值JTA时,glassfish再次给了我错误信息,
[#| 2011-06-24T18:46:48.955 + 0200 |警告| glassfish3.1 | org.apache.catalina .connector.Request | _ThreadID = 24; _ThreadName = Thread-3; | PWC4011:由于请求参数已被读取,或ServletRequest.getReader()已被调用,所以无法从上下文将请求字符编码设置为UTF-8。 #]
[#| 2011-06-24T18:46:49.185 + 0200 | INFO | glassfish3.1 | javax.enterprise.system.std.com.sun.enterprise.server.logging | _ThreadID = 88; _ThreadName = Thread-3; | ===== GUI部署:needUploadToTempfile ====== |#]
[#| 2011-06-24T18:46:49.197 + 0200 | INFO | glassfish3.1 | org.glassfish.admingui | _ThreadID = 24; _ThreadName = Thread-3; | ======= uploadFileName = webFrontend-1.0-SNAPSHOT.war |#]
[#| 2011-06-24T18:46:49.201 + 0200 | INFO | glassfish3.1 | javax.enterprise.system.std.com.sun.enterprise.server.logging | _ThreadID = 88; _ThreadName = Threa d-3; | ===== filePath = / private / var / folders / m + / m + kO87fOGXS5o7r3iUMGR ++++ TI / -Tmp- / webFrontend -17474491606051515474.0-SNAPSHOT.war origPath = webFrontend-1 |#]
[#| 2011-06-24T18:46:54.765 + 0200 | INFO | glassfish3.1 | org.hibernate.validator.engine.resolver.DefaultTraversableResolver | _ThreadID = 24; _ThreadName = Thread-3; |实例化org.hibernate.validator.engine.resolver.JPATraversableResolver的一个实例。|#]
[#| 2011-06-24T18:46:55.672 + 0200 | SEVERE | glassfish3.1 | javax .enterprise.system.std.com.sun.enterprise.server.logging | _ThreadID = 88; _ThreadName = Thread-3; | log4j:错误org.apache.log4j.ConsoleAppender对象不可分配给组织。 apache.log4j.Appender变量。|#]
[#| 2011-06-24T18:46:55.672 + 0200 | SEVERE | glassfish3.1 | javax.enterprise.system.std.com。 sun.enterprise.server.logging | _ThreadID = 88; _ThreadName = Thread-3; | log4j:错误类org.apache.log4j.Appender由|#]
[#| 2011-06-24T18:46:55.672 + 0200 |严重| glassfish3.1 | javax.enterprise.sy我们可以使用下面的代码来创建一个Web应用程序:代码=真正的Web应用程序。而类型的对象|#]
[#| 2011-06-24T18:46:55.672 + 0200 | SEVERE | glassfish3.1 | javax.enterprise。 system.std.com.sun.enterprise.server.logging | _ThreadID = 88; _ThreadName = Thread-3; | log4j:ERRORorg.apache.log4j.ConsoleAppender已由[WebappClassLoader(delegate = true; repositories = WEB -INF / classes /)]。|#]
[#| 2011-06-24T18:46:55.673 + 0200 | SEVERE | glassfish3.1 | javax.enterprise.system.std.com。 sun.enterprise.server.logging | _ThreadID = 88; _ThreadName = Thread-3; | log4j:ERROR无法实例化名为stdout的appender。|#]
[#| 2011-06-24T18 :46:56.980 + 0200 | INFO | glassfish3.1 | org.hibernate.validator.engine.resolver.DefaultTraversableResolver | _ThreadID = 24; _ThreadName = Thread-3; |实例化org.hibernate.validator.engine.resolver的一个实例。 。JPATraversableResolver |#]
[#| 2011-06-24T18:46:57.403 + 0200 | INFO | glassfish3.1 | org.hibernate.validator.engine.resolver.DefaultTraversableResolver | _ThreadID = 24; _ThreadName =螺纹-3; | Instan提供org.hibernate.validator.engine.resolver.JPATraversableResolver的实例。|#]
[#| 2011-06-24T18:46:57.409 + 0200 | INFO | glassfish3.1 | org。 hibernate.validator.engine.resolver.DefaultTraversableResolver | _ThreadID = 24; _ThreadName = Thread-3; |实例化org.hibernate.validator.engine.resolver.JPATraversableResolver的一个实例。|#]
[# | 2011-06-24T18:46:57.773 + 0200 |警告| glassfish3.1 | javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.allocator | _ThreadID = 88; _ThreadName =螺纹-3; | RAR5038:为池DerbyPool创建资源时发生意外的异常。异常:javax.resource.spi.ResourceAllocationException:无法分配连接,因为:java.net.ConnectException:在消息连接被拒绝的情况下连接到服务器本地主机的端口1527时出错。|#]
[#| 2011-06-24T18:46:57.801 + 0200 |警告| glassfish3.1 | javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors | _ThreadID = 88; _ThreadName = Thread-3; | RAR5117:无法获取/从连接池[DerbyPool]创建连接。原因:com.sun.appserv.connectors.internal.api.PoolingException:连接无法分配,因为:java.net.ConnectException:在端口1527连接到服务器本地主机时出现连接被拒绝错误。|#]
[#| 2011-06-24T18:46:57.831 + 0200 |警告| glassfish3.1 | javax.enterprise.resource.resourceadapter.com.sun.gjc.spi | _ThreadID = 88; _ThreadName = Thread-3; | RAR5114:分配连接时出错:[分配连接时出错。原因:无法分配连接,因为:java.net.ConnectException:在消息连接被拒绝的情况下连接到端口1527上的服务器本地主机时发生错误。] |#]
[#| 2011-06-24T18:46 :58.232 + 0200 | INFO | glassfish3.1 | org.hibernate.validator.engine.resolver.DefaultTraversableResolver | _ThreadID = 24; _ThreadName = Thread-3; |实例化org.hibernate.validator.engine.resolver.JPATraversableResolver的一个实例。 |#]
[#| 2011-06-24T18:46:58.237 + 0200 | INFO | glassfish3.1 | org.hibernate.validator.engine.resolver.DefaultTraversableResolver | _ThreadID = 24; _ThreadName = Thread-3; |实例化了org.hibernate.validator.engine.resolver.JPATraversableResolver的实例。|#]
[#| 2011-06-24T18:46:58.249 + 0200 |警告| glassfish3 .1 | javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.allocator | _ThreadID = 88; _ThreadName = Thread-3; | RAR5038:为池DerbyPool创建资源时发生意外的异常。异常:javax.resource.spi.ResourceAllocationException:无法分配连接,因为:java.net.ConnectException:在消息连接被拒绝的情况下连接到服务器本地主机的端口1527时出错。|#]
[#| 2011-06-24T18:46:58.250 + 0200 |警告| glassfish3.1 | javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors | _ThreadID = 88; _ThreadName = Thread-3; | RAR5117:无法获取/从连接池[DerbyPool]创建连接。原因:com.sun.appserv.connectors.internal.api.PoolingException:连接无法分配,因为:java.net.ConnectException:在端口1527连接到服务器本地主机时出现连接被拒绝错误。|#]
[#| 2011-06-24T18:46:58.251 + 0200 | WARNING | glassfish3.1 | javax.enterprise.resource.resourceadapter.com.sun.gjc.spi | _ThreadID = 88; _ThreadName = Thread-3; | RAR5114:分配连接时出错:[分配连接时出错。原因:无法分配连接,因为:java.net.ConnectException:在消息连接被拒绝的情况下连接到端口1527上的服务器本地主机时发生错误。] |#]
[#| 2011-06-24T18:46 :58.257 + 0200 | SEVERE | glassfish3.1 | javax.enterprise.system.std.com.sun.enterprise.server.logging | _ThreadID = 88; _ThreadName = Thread-3; | log4j:WARN记录器不能找到appender (org.hibernate.tool.hbm2ddl.SchemaExport)。|#]
[#| 2011-06-24T18:46:58.257 + 0200 | SEVERE | glassfish3.1 | javax.enterprise.system。 std.com.sun.enterprise.server.logging | _ThreadID = 88; _ThreadName = Thread-3; | log4j:WARN请正确初始化log4j系统。|#]
[#| 2011-06 -24T18:46:58.257 + 0200 | SEVERE | glassfish3.1 | javax.enterprise.system.std.com.sun.enterprise.server.logging | _ThreadID = 88; _ThreadName = Thread-3; | log4j:WARN请参阅http: //logging.apache.org/log4j/1.2/faq.html#noconfig for more info。|#]
[#| 2011-06-24T18:46:58.727 + 0200 | INFO | glassfish3 0.1 | javax.enterprise.system.container.web.com.sun.enterp | | | | | $ | $ | $ | $ | $ | $ | $ | $ | $ | $ | $ | $ :47:00.642 + 0200 | INFO | glassfish3.1 | org.hibernate.validator.engine.resolver.DefaultTraversableResolver | _ThreadID = 24; _ThreadName = Thread-3; |实例化org.hibernate.validator.engine.resolver的一个实例。 。JPATraversableResolver |#]
[#| 2011-06-24T18:47:00.648 + 0200 | INFO | glassfish3.1 | org.hibernate.validator.engine.resolver.DefaultTraversableResolver | _ThreadID = 24; _ThreadName = Thread-3; |实例化org.hibernate.validator.engine.resolver.JPATraversableResolver的一个实例。|#]
[#| 2011-06-24T18:47:00.651 + 0200 | INFO | glassfish3.1 | org.hibernate.validator.engine.resolver.DefaultTraversableResolver | _ThreadID = 24; _ThreadName = Thread-3; |实例化org.hibernate.validator.engine.resolver.JPATraversableResolver的一个实例。 b
[#| 2011-06-24T18:47:01.277 + 0200 | INFO | glassfish3.1 | org.hibernate.validator.e ngine.resolver.DefaultTraversableResolver | _ThreadID = 24; _ThreadName = Thread-3; |实例化org.hibernate.validator.engine.resolver.JPATraversableResolver的一个实例。|#]
[#| 2011-06 -24T18:47:01.279 + 0200 | INFO | glassfish3.1 | org.hibernate.validator.engine.resolver.DefaultTraversableResolver | _ThreadID = 24; _ThreadName = Thread-3; |实例化org.hibernate.validator.engine的实例。 resolver.JPATraversableResolver。|#]
[#| 2011-06-24T18:47:01.336 + 0200 | SEVERE | glassfish3.1 | org.apache.catalina.core.StandardContext | _ThreadID = 24; _ThreadName = Thread-3; | PWC1306:启动上下文/webFrontend-1.0-SNAPSHOT失败,因为以前的错误|#]
[#| 2011-06-24T18:47:01.512 + 0200 | SEVERE | glassfish3.1 | org.apache.catalina.core.StandardContext | _ThreadID = 24; _ThreadName = Thread-3; | PWC1305:启动失败后的清理过程中的异常
org.apache.catalina.LifecycleException:PWC2769:Manager has尚未在org.apache.catalina.session.StandardManager.stop上开始
(Stan dardManager.java:872)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:5509)
at com.sun.enterprise.web.WebModule.stop(WebModule.java: 529)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5323)
at com.sun.enterprise.web.WebModule.start(WebModule.java:500)$ b在org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
$ b在org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
。在组织.apache.catalina.core.StandardHost.addChild(StandardHost.java:755)
在com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1980)
在com.sun.enterprise .web.WebContainer.loadWebModule(WebContainer.java:1630)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:100)
at org.glassfish.internal.data.EngineRef .start(EngineRef.java:130)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:286)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:370)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
$ com.RunnerImpl $ 1.execute(CommandRunnerImpl.java:355)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1067)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access $ 1200(CommandRunnerImpl.java:96)
在com.sun.enterprise.v3.admin.CommandRunnerImpl $ ExecutionContext.execute(CommandRunnerImpl.java:1247)
at com.sun.enterprise.v3.admin.CommandRunnerImpl $ ExecutionContext.execute(CommandRunnerImpl.java:1235 )$或$ b $ at或g.glassfish.admingui.common.util.LocalDeploymentFacility $ LocalDFCommandRunner.run(LocalDeploymentFacility.java:143)
at org.glassfish.deployment.client.AbstractDeploymentFacility.deploy(AbstractDeploymentFacility.java:406)
at org.glassfish.admingui.common.util.DeployUtil.invokeDeploymentFacility(DeployUtil.java:100)
at org.glassfish.admingui.common.util.DeployUtil.deploy(DeployUtil.java:76)
at org.glassfish.admingui.common.handlers.DeploymentHandler.deploy(DeploymentHandler.java:191)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl .java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.jsftemplating.layout.descriptors.handler.Handler.invoke(Handler.java:442)
at com.sun.jsftemplating.layout.descriptors.LayoutEl在com.sun.jsftemplating.layout.descriptors.LayoutElementBase.dispatchHandlers ementBase.dispatchHandlers(LayoutElementBase.java:420)
(LayoutElementBase.java:394)
。在com.sun.jsftemplating.layout.event。 CommandActionListener.invokeCommandHandlers(CommandActionListener.java:150)
在com.sun.jsftemplating.layout.event.CommandActionListener.processAction(CommandActionListener.java:98)
在javax.faces.event.ActionEvent.processListener( ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at com.sun.webui.jsf.component.WebuiCommand.broadcast(WebuiCommand.java:166)
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)
在javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
在org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
在org.apache.catalina .core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
在com.sun.webui.jsf.util .UploadFilter.doFilter(UploadFilter.java:223)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.jav a:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.doChainInvoke(StandardPipeline.java:600)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:96)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
在org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
在org.apache .catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:228)
at com.sun .grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
在com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
在com.sun.grizzly.http .ProcessorTask.process(ProcessorTask.java:1013)
在com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
在com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
在com.sun.grizzly .DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
在com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)在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:680)
|#]
[#| 2011-06-24T18:47:01.514 + 0200 | SEVERE | g lassfish3.1 | org.apache.catalina.core.ContainerBase | _ThreadID = 24; _ThreadName = Thread-3; | ContainerBase.addChild:start:
org.apache.catalina.LifecycleException:org.springframework.beans.factory .BeanCreationException:创建名为'PersonDao'的bean时出错:持久性依赖关系注入失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:在URL中定义名称为'entityManagerFactory'的bean时出错[file:/opt/glassfish3/glassfish/domains/domain1/applications/webFrontend-1.0-SNAPSHOT/WEB-INF/ classes / META-INF / spring / applicationContext-persistence.xml]:调用init方法失败;嵌套异常是javax.persistence.PersistenceException:[PersistenceUnit:basicPersistenceUnit]无法在org.apache.catalina.core.StandardContext.start(StandardContext.java:5328)上创建EntityManagerFactory
...
tomcat也给我一个JTA错误:
ERROR org.springframework.web.context.ContextLoader - 上下文初始化失败
org.springframework.beans.factory。 BeanCreationException:创建名为'PersonDao'的Bean时出错:持久性依赖项的注入失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:在URL中定义名称为'entityManagerFactory'的bean时出错[file:/opt/apache-tomcat-7.0.16/webapps/webFrontend-1.0-SNAPSHOT/WEB-INF/ classes / META-INF / spring / applicationContext-persistence.xml]:调用init方法失败;嵌套异常是javax.persistence.PersistenceException:[PersistenceUnit:basicPersistenceUnit]无法在org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues构建的EntityManagerFactory
(PersistenceAnnotationBeanPostProcessor.java:341)在有机
。 springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
。在组织。 springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:291)
。在组织.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
a t org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)在org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
。在组织.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web .context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
在org.apache.catalina.core.Standa rdContext.listenerStart(StandardContext.java:4723)
在org.apache.catalina.core.StandardContext $ 1.call(StandardContext.java:5226)
在org.apache.catalina.core.StandardContext $ 1。在java.util.concurrent.FutureTask中调用(StandardContext.java:5221)
$ Sync.innerRun(FutureTask.java:303)$ java.util.concurrent.FutureTask.run中的
(FutureTask.java: 138)
在java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(ThreadPoolExecutor.java:886)$ b $在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:908)
在java.lang.Thread.run(Thread.java:680)
导致:org.springframework.beans.factory.BeanCreationException:在URL中定义的名称为'entityManagerFactory'的bean创建错误[file:/ opt /apache-tomcat-7.0.16/webapps/webFrontend-1.0-SNAPSHOT/WEB-INF/classes/META-INF/spring/applicationContext-persistence.xml]:调用init方法失败;嵌套异常是javax.persistence.PersistenceException:[PersistenceUnit:basicPersistenceUnit]无法在组织构建在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
的EntityManagerFactory
。 springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org。 springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org .springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)$ or
at org.springframework.beans.factory.support.Ab在org.springframework.orm.jpa.support上
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:529)
。 PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:495)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor $ PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:656)
at org.springframework.orm.jpa。 support.PersistenceAnnotationBeanPostProcessor $ PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:629)维持在org.springframework org.springframework.beans.factory.annotation.InjectionMetadata $ InjectedElement.inject(InjectionMetadata.java:156)
。 beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframewo rk.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:338)
... 21 more
导致:javax.persistence.PersistenceException:[PersistenceUnit:basicPersistenceUnit]无法构建EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
at org.springframework。 orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
位于org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
位于org.springframework.beans.factory。支持.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
在org.springframework.beans.factory .support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 34多个
引起的:org.hibernate.HibernateException:所选择的交易策略需要访问JTA事务管理
。在org.hibernate.impl.SessionFactoryImpl。< init>(SessionFactoryImpl.java:390)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at org.hibernate.ejb .Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)
... 39 more
所以我会问,这是什么参数?我读了Hibernate站点上的定义:如果在JavaEE环境中使用,则事务类型必须为JTA。当GlassFish和Tomcat是JavaEE应用程序容器时,为什么当我在Tomcat上使用RESOURCE_LOCAL时一切正常。我在哪里错误参数是JTA,并且这两个应用程序容器都给我一个错误?解析方案
从官方的Oracle JTA技术站点:Java Transaction API(JTA)指定事务管理器与分布式事务系统中涉及的各方之间的标准Java接口:资源管理器,应用程序服务器和事务应用程序。 意味着当一些软件需求涉及多个原子行为时,您应该将它们分组在一个事务中,以便它们都发生在一起,或者它们都不会发生。银行账户资金转账的着名例子显示了交易需求(从一个到$,另一个是两个原子操作)。对于Java EE环境,原子动作可能涉及许多不同的技术,可以通过应用程序服务器使用JTA进行控制。
现在回答您的问题:可能您没有使用JTA ...如果你使用这样的代码,
this.manager = JPAUtility.getEntityManager();
this.manager.getTransaction()。begin();
this.manager.persist(entidadeGenerica);
this.manager.getTransaction()。commit();
this.manager.refresh(entidadeGenerica);
this.manager.close();
(可能在您的DAO实体中),意味着您自己控制事务( getTransation )),并且不会通过JTA处理它们。因此,您必须使用RESOURCE_LOCAL。
最后,使用JTA配置时遇到问题,因为它需要更多配置和/或一行代码工作,主要指出哪些JTA的经理和规则应该在特定情况下使用。
PS .: Tomcat不是应用程序容器,因为它只实现了Web容器规范Servlets和相关)...搜索Stackoverflow为此,你会证实这一点。
I have a question about persistence.xml config parameter "transaction-type". If I set this parameter to value "RESOURCE_LOCAL", than application run fine in tomcat application server. But not in glassfish. Glassfish gave me next error:
The persistence-context-ref-name [com.test.webtest.persistence.dao.jpa.AbstractGenericDaoJpa/entityManager] in module [webFrontend-1.0-SNAPSHOT] resolves to a persistence unit called [basicPersistenceUnit] which is of type RESOURCE_LOCAL. Only persistence units with transaction type JTA can be used as a container managed entity manager. Please verify your application.
java.lang.RuntimeException: The persistence-context-ref-name [com.test.webtest.persistence.dao.jpa.AbstractGenericDaoJpa/entityManager] in module [webFrontend-1.0-SNAPSHOT] resolves to a persistence unit called [basicPersistenceUnit] which is of type RESOURCE_LOCAL. Only persistence units with transaction type JTA can be used as a container managed entity manager. Please verify your application.
When I change the parameter to value "JTA", then glassfish gave me error again, but another:
[#|2011-06-24T18:46:48.955+0200|WARNING|glassfish3.1|org.apache.catalina.connector.Request|_ThreadID=24;_ThreadName=Thread-3;|PWC4011: Unable to set request character encoding to UTF-8 from context , because request parameters have already been read, or ServletRequest.getReader() has already been called|#]
[#|2011-06-24T18:46:49.185+0200|INFO|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=88;_ThreadName=Thread-3;|===== GUI deployment: needUploadToTempfile ======|#]
[#|2011-06-24T18:46:49.197+0200|INFO|glassfish3.1|org.glassfish.admingui|_ThreadID=24;_ThreadName=Thread-3;|======= uploadFileName=webFrontend-1.0-SNAPSHOT.war|#]
[#|2011-06-24T18:46:49.201+0200|INFO|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=88;_ThreadName=Thread-3;|===== filePath=/private/var/folders/m+/m+kO87fOGXS5o7r3iUMGR++++TI/-Tmp-/webFrontend-17474491606051515474.0-SNAPSHOT.war origPath=webFrontend-1|#]
[#|2011-06-24T18:46:54.765+0200|INFO|glassfish3.1|org.hibernate.validator.engine.resolver.DefaultTraversableResolver|_ThreadID=24;_ThreadName=Thread-3;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.|#]
[#|2011-06-24T18:46:55.672+0200|SEVERE|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=88;_ThreadName=Thread-3;|log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.|#]
[#|2011-06-24T18:46:55.672+0200|SEVERE|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=88;_ThreadName=Thread-3;|log4j:ERROR The class "org.apache.log4j.Appender" was loaded by |#]
[#|2011-06-24T18:46:55.672+0200|SEVERE|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=88;_ThreadName=Thread-3;|log4j:ERROR [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)] whereas object of type |#]
[#|2011-06-24T18:46:55.672+0200|SEVERE|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=88;_ThreadName=Thread-3;|log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)].|#]
[#|2011-06-24T18:46:55.673+0200|SEVERE|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=88;_ThreadName=Thread-3;|log4j:ERROR Could not instantiate appender named "stdout".|#]
[#|2011-06-24T18:46:56.980+0200|INFO|glassfish3.1|org.hibernate.validator.engine.resolver.DefaultTraversableResolver|_ThreadID=24;_ThreadName=Thread-3;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.|#]
[#|2011-06-24T18:46:57.403+0200|INFO|glassfish3.1|org.hibernate.validator.engine.resolver.DefaultTraversableResolver|_ThreadID=24;_ThreadName=Thread-3;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.|#]
[#|2011-06-24T18:46:57.409+0200|INFO|glassfish3.1|org.hibernate.validator.engine.resolver.DefaultTraversableResolver|_ThreadID=24;_ThreadName=Thread-3;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.|#]
[#|2011-06-24T18:46:57.773+0200|WARNING|glassfish3.1|javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.allocator|_ThreadID=88;_ThreadName=Thread-3;|RAR5038:Unexpected exception while creating resource for pool DerbyPool. Exception : javax.resource.spi.ResourceAllocationException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.|#]
[#|2011-06-24T18:46:57.801+0200|WARNING|glassfish3.1|javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors|_ThreadID=88;_ThreadName=Thread-3;|RAR5117 : Failed to obtain/create connection from connection pool [ DerbyPool ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.|#]
[#|2011-06-24T18:46:57.831+0200|WARNING|glassfish3.1|javax.enterprise.resource.resourceadapter.com.sun.gjc.spi|_ThreadID=88;_ThreadName=Thread-3;|RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.]|#]
[#|2011-06-24T18:46:58.232+0200|INFO|glassfish3.1|org.hibernate.validator.engine.resolver.DefaultTraversableResolver|_ThreadID=24;_ThreadName=Thread-3;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.|#]
[#|2011-06-24T18:46:58.237+0200|INFO|glassfish3.1|org.hibernate.validator.engine.resolver.DefaultTraversableResolver|_ThreadID=24;_ThreadName=Thread-3;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.|#]
[#|2011-06-24T18:46:58.249+0200|WARNING|glassfish3.1|javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.allocator|_ThreadID=88;_ThreadName=Thread-3;|RAR5038:Unexpected exception while creating resource for pool DerbyPool. Exception : javax.resource.spi.ResourceAllocationException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.|#]
[#|2011-06-24T18:46:58.250+0200|WARNING|glassfish3.1|javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors|_ThreadID=88;_ThreadName=Thread-3;|RAR5117 : Failed to obtain/create connection from connection pool [ DerbyPool ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.|#]
[#|2011-06-24T18:46:58.251+0200|WARNING|glassfish3.1|javax.enterprise.resource.resourceadapter.com.sun.gjc.spi|_ThreadID=88;_ThreadName=Thread-3;|RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.]|#]
[#|2011-06-24T18:46:58.257+0200|SEVERE|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=88;_ThreadName=Thread-3;|log4j:WARN No appenders could be found for logger (org.hibernate.tool.hbm2ddl.SchemaExport).|#]
[#|2011-06-24T18:46:58.257+0200|SEVERE|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=88;_ThreadName=Thread-3;|log4j:WARN Please initialize the log4j system properly.|#]
[#|2011-06-24T18:46:58.257+0200|SEVERE|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=88;_ThreadName=Thread-3;|log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.|#]
[#|2011-06-24T18:46:58.727+0200|INFO|glassfish3.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=88;_ThreadName=Thread-3;|PWC1412: WebModule[null] ServletContext.log():Initializing Spring root WebApplicationContext|#]
[#|2011-06-24T18:47:00.642+0200|INFO|glassfish3.1|org.hibernate.validator.engine.resolver.DefaultTraversableResolver|_ThreadID=24;_ThreadName=Thread-3;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.|#]
[#|2011-06-24T18:47:00.648+0200|INFO|glassfish3.1|org.hibernate.validator.engine.resolver.DefaultTraversableResolver|_ThreadID=24;_ThreadName=Thread-3;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.|#]
[#|2011-06-24T18:47:00.651+0200|INFO|glassfish3.1|org.hibernate.validator.engine.resolver.DefaultTraversableResolver|_ThreadID=24;_ThreadName=Thread-3;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.|#]
[#|2011-06-24T18:47:01.277+0200|INFO|glassfish3.1|org.hibernate.validator.engine.resolver.DefaultTraversableResolver|_ThreadID=24;_ThreadName=Thread-3;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.|#]
[#|2011-06-24T18:47:01.279+0200|INFO|glassfish3.1|org.hibernate.validator.engine.resolver.DefaultTraversableResolver|_ThreadID=24;_ThreadName=Thread-3;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.|#]
[#|2011-06-24T18:47:01.336+0200|SEVERE|glassfish3.1|org.apache.catalina.core.StandardContext|_ThreadID=24;_ThreadName=Thread-3;|PWC1306: Startup of context /webFrontend-1.0-SNAPSHOT failed due to previous errors|#]
[#|2011-06-24T18:47:01.512+0200|SEVERE|glassfish3.1|org.apache.catalina.core.StandardContext|_ThreadID=24;_ThreadName=Thread-3;|PWC1305: Exception during cleanup after start failed
org.apache.catalina.LifecycleException: PWC2769: Manager has not yet been started
at org.apache.catalina.session.StandardManager.stop(StandardManager.java:872)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:5509)
at com.sun.enterprise.web.WebModule.stop(WebModule.java:529)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5323)
at com.sun.enterprise.web.WebModule.start(WebModule.java:500)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:755)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1980)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1630)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:100)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:286)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:370)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:355)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1067)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1247)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
at org.glassfish.admingui.common.util.LocalDeploymentFacility$LocalDFCommandRunner.run(LocalDeploymentFacility.java:143)
at org.glassfish.deployment.client.AbstractDeploymentFacility.deploy(AbstractDeploymentFacility.java:406)
at org.glassfish.admingui.common.util.DeployUtil.invokeDeploymentFacility(DeployUtil.java:100)
at org.glassfish.admingui.common.util.DeployUtil.deploy(DeployUtil.java:76)
at org.glassfish.admingui.common.handlers.DeploymentHandler.deploy(DeploymentHandler.java:191)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.jsftemplating.layout.descriptors.handler.Handler.invoke(Handler.java:442)
at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.dispatchHandlers(LayoutElementBase.java:420)
at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.dispatchHandlers(LayoutElementBase.java:394)
at com.sun.jsftemplating.layout.event.CommandActionListener.invokeCommandHandlers(CommandActionListener.java:150)
at com.sun.jsftemplating.layout.event.CommandActionListener.processAction(CommandActionListener.java:98)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at com.sun.webui.jsf.component.WebuiCommand.broadcast(WebuiCommand.java:166)
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:409)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at com.sun.webui.jsf.util.UploadFilter.doFilter(UploadFilter.java:223)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
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.doChainInvoke(StandardPipeline.java:600)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:96)
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:326)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:228)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
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:680)
|#]
[#|2011-06-24T18:47:01.514+0200|SEVERE|glassfish3.1|org.apache.catalina.core.ContainerBase|_ThreadID=24;_ThreadName=Thread-3;|ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PersonDao': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/opt/glassfish3/glassfish/domains/domain1/applications/webFrontend-1.0-SNAPSHOT/WEB-INF/classes/META-INF/spring/applicationContext-persistence.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: basicPersistenceUnit] Unable to build EntityManagerFactory
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5328)
...
And tomcat gave me an error with "JTA" too:
ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PersonDao': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/opt/apache-tomcat-7.0.16/webapps/webFrontend-1.0-SNAPSHOT/WEB-INF/classes/META-INF/spring/applicationContext-persistence.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: basicPersistenceUnit] Unable to build EntityManagerFactory
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/opt/apache-tomcat-7.0.16/webapps/webFrontend-1.0-SNAPSHOT/WEB-INF/classes/META-INF/spring/applicationContext-persistence.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: basicPersistenceUnit] Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:529)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:495)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:656)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:629)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:156)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:338)
... 21 more
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: basicPersistenceUnit] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 34 more
Caused by: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:390)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)
... 39 more
So I would ask, for what is this parameter for? I read definition on Hibernate site: Transaction type must be "JTA" if is used in JavaEE enviroment. When GlassFish and Tomcat are JavaEE app containers, why when I'm using "RESOURCE_LOCAL" on Tomcat works all fine. And where do I mistake when parameter is "JTA" and both app containers gave me an error?
解决方案
From the official Oracle JTA technology site: "Java Transaction API (JTA) specifies standard Java interfaces between a transaction manager and the parties involved in a distributed transaction system: the resource manager, the application server, and the transactional applications." It means that when some software requirement involves more than one "atomic" action, you should group them inside a transaction so they all happen together or none of them happens. The famous example of bank accounts money transfer shows the transaction need (take $ from one and sum $ at the other are two atomic actions). For a Java EE environment the atomic action may involve a lot of different technologies that can be controlled using JTA via application servers.
Now answering your question: probably you are not using JTA... if you are using code like this,
this.manager = JPAUtility.getEntityManager();
this.manager.getTransaction().begin();
this.manager.persist(entidadeGenerica);
this.manager.getTransaction().commit();
this.manager.refresh(entidadeGenerica);
this.manager.close();
(probably in you DAO entities), means you are controlling the transactions yourself (getTransation()), and will not handle them via JTA. So you have to use "RESOURCE_LOCAL".
Finally, you are having problems using the "JTA" configuration, because it asks for more configurations and/or lines of code to work, mainly pointing which JTA's managers and rules should be used at specific cases.
PS.: Tomcat is not an app container because it implements only the web container specifications (basically Servlets and related)... Search Stackoverflow for this that you will confirm this.
这篇关于持久性事务类型值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!