Context initialization failed - mit Spring, JPA, Hibernate

Pikolu

Mitglied
Hallo Zusammen,

Ich schreibe zuzeit eine Spring mvc Anwenung.

Ich versuche mich gerade an JPA zu verbinden und benutze dazu Hibernate.

Dazu benutze ich Netbeans 7.2.1 und Glassfish 3.1.2.

Beim Deployen der Anwendung bekomme ich folgende Fehlermeldung

Java:
INFO: 20:56:53.967 [admin-thread-pool-4848(1)] ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: lmoneta] Unable to build EntityManagerFactory
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-2.5.6.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) ~[spring-2.5.6.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) ~[spring-2.5.6.jar:na]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_11]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) ~[spring-2.5.6.jar:na]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) ~[spring-2.5.6.jar:na]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-2.5.6.jar:na]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) ~[spring-2.5.6.jar:na]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) ~[spring-2.5.6.jar:na]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) ~[spring-2.5.6.jar:na]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423) ~[spring-2.5.6.jar:na]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) ~[spring-2.5.6.jar:na]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380) ~[spring-2.5.6.jar:na]
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) ~[spring-2.5.6.jar:na]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) ~[spring-2.5.6.jar:na]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) [spring-2.5.6.jar:na]
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:4750) [web-core.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:550) [web-glue.jar:3.1.2.1-SNAPSHOT]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5366) [web-core.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.web.WebModule.start(WebModule.java:498) [web-glue.jar:3.1.2.1-SNAPSHOT]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917) [web-core.jar:3.1.2.1-SNAPSHOT]
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901) [web-core.jar:3.1.2.1-SNAPSHOT]
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733) [web-core.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2019) [web-glue.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669) [web-glue.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109) [web-glue.jar:3.1.2.1-SNAPSHOT]
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130) [internal-api.jar:3.1.2.1-SNAPSHOT]
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269) [internal-api.jar:3.1.2.1-SNAPSHOT]
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301) [internal-api.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461) [kernel.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240) [kernel.jar:3.1.2.1-SNAPSHOT]
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389) [deployment-admin.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348) [kernel.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363) [kernel.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085) [kernel.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95) [kernel.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291) [kernel.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259) [kernel.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461) [kernel.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212) [kernel.jar:3.1.2.1-SNAPSHOT]
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179) [grizzly-utils.jar:1.9.50]
    at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117) [kernel.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354) [kernel.jar:3.1.2.1-SNAPSHOT]
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) [kernel.jar:3.1.2.1-SNAPSHOT]
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860) [grizzly-http.jar:1.9.50]
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757) [grizzly-http.jar:1.9.50]
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056) [grizzly-http.jar:1.9.50]
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229) [grizzly-http.jar:1.9.50]
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) [grizzly-framework.jar:1.9.50]
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) [grizzly-framework.jar:1.9.50]
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) [grizzly-framework.jar:1.9.50]
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) [grizzly-http.jar:1.9.50]
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) [grizzly-framework.jar:1.9.50]
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) [grizzly-framework.jar:1.9.50]
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71) [grizzly-framework.jar:1.9.50]
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) [grizzly-utils.jar:1.9.50]
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) [grizzly-utils.jar:1.9.50]
    at java.lang.Thread.run(Thread.java:722) [na:1.7.0_11]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: lmoneta] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677) ~[hibernate-entitymanager-3.3.2.GA.jar:na]
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:132) ~[hibernate-entitymanager-3.3.2.GA.jar:na]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:224) ~[spring-2.5.6.jar:na]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:291) ~[spring-2.5.6.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369) ~[spring-2.5.6.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335) ~[spring-2.5.6.jar:na]
    ... 57 common frames omitted
Caused by: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:329) ~[hibernate-3.2.5.ga.jar:na]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294) ~[hibernate-3.2.5.ga.jar:na]
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859) ~[hibernate-annotations-3.3.1.GA.jar:na]
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669) ~[hibernate-entitymanager-3.3.2.GA.jar:na]
    ... 62 common frames omitted
 
SEVERE: PWC1306: Startup of context /lmoneta-web failed due to previous errors
SEVERE: 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:873)
    at org.apache.catalina.core.StandardContext.stop(StandardContext.java:5571)
    at com.sun.enterprise.web.WebModule.stop(WebModule.java:527)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5384)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
    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:733)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2019)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    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:301)
    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:389)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    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:722)

Hier noch meine persistence.xml und applicationContext.xml

persistence.xml
Java:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans [url]http://www.springframework.org/schema/beans/spring-beans-2.5.xsd[/url]
       [url=http://www.springframework.org/schema/aop]Index of /schema/aop[/url] [url]http://www.springframework.org/schema/aop/spring-aop-2.5.xsd[/url]
       [url=http://www.springframework.org/schema/tx]Index of /schema/tx[/url] http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
 
    <bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"
          p:driverClassName="com.mysql.jdbc.Driver"
          p:url="jdbc:mysql://localhost:3306/lmoneta?zeroDateTimeBehavior=convertToNull"
          p:username="root"
          p:password="" />
    
 
    <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />
                <property name="generateDdl" value="true" />
                <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
            </bean>
        </property>
        <property name="persistenceUnitName" value="lmoneta" />
        <property name="dataSource" ref="dataSource" />
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" >
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
</beans>

applicationContext.xml
Java:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="lmoneta" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>lmoneta</jta-data-source>
    <class>com.lmoneta.dbmodel.User</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
  </persistence-unit>
</persistence>
 
Zuletzt bearbeitet von einem Moderator:

F.S.WhiTeY

Bekanntes Mitglied
Caused by: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager

Ein blick auf den Root-Cause ist immer hilfreich ;)

BTW: Wenn du Hibernate benutzt solltest du auch den Hibernate Transaktionsmanager verwenden. Könnte eine mögliche uhrsache sein.

[XML]
<property name="hibernate.transaction.manager_lookup_class" value="Hier bin ich mir gerade nicht sicher, google wird dir helfen"/>
[/XML]
 

Neue Themen


Oben