복붙노트

[SPRING] GWT Dev 모드 + Spring 3.1 + Hibernate 4.0.1의 예외

SPRING

GWT Dev 모드 + Spring 3.1 + Hibernate 4.0.1의 예외

나는 Spring 3.0.x + Hibernate 3.6.x에서 OK 인 GWT + Hibernate + JPA + Spring 설정 파일을 가지고있다. Spring 3.1과 Hibernate 4.0으로 업그레이드했을 때, 다음과 같은 예외가 발생합니다 :

Hibernate 4와 Spring 3.1에 알려진 호환성이 있습니까?

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [META-INF/application-context.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: myPu] Unable to build EntityManagerFactory
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
    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:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
    at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:222)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
    at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
    at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)
    at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)
    at com.google.gwt.dev.DevMode.main(DevMode.java:311)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: naftPu] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:257)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
    ... 30 more
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:187)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:234)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:91)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2270)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2266)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1735)
    at org.hibernate.ejb.EntityManagerFactoryImpl.(EntityManagerFactoryImpl.java:84)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
    ... 36 more
Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider]
    at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:190)
    at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:112)
    at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:54)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:69)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:177)
    ... 49 more
Caused by: java.lang.ClassCastException: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider cannot be cast to org.hibernate.service.jdbc.connections.spi.ConnectionProvider
    at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:187)
    ... 53 more

다음은 내 application-context.xml 구성의 일부입니다.

<bean id="mainDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.OracleDriver" />
    <property name="url" value="***manually deleted***" />
    <property name="username" value="myschema" />
    <property name="password" value="myschema" />
    <property name="initialSize" value="1" />
    <property name="maxActive" value="4" />
    <property name="maxIdle" value="-1" />
    <property name="maxWait" value="10000" />
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:persistenceUnitName="myPu">
    <property name="dataSource" ref="mainDataSource" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" p:showSql="true" p:generateDdl="true"
            p:database="ORACLE" p:databasePlatform="org.hibernate.dialect.Oracle10gDialect" />
    </property>
    <property name="jpaPropertyMap">
        <map merge="true">
            <entry key="hibernate.archive.autodetection" value="class" />
            <entry key="hibernate.format_sql" value="false" />
            <entry key="hibernate.hbm2ddl.auto" value="false" />
            <entry key="hibernate.default_schema" value="myschema" />
        </map>
    </property>
</bean>

persistence.xml :

<persistence 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_2_0.xsd" version="2.0">
    <persistence-unit name="myPu" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
    </persistence-unit>
</persistence>

해결법

  1. ==============================

    1.이 문제는 Hibernate 4.1.4에서 수정되었다.

    이 문제는 Hibernate 4.1.4에서 수정되었다.

    나는 같은 문제가 있었고, Jetty 클래스 로더 (GWT 플러그인은 호스트 모드 용으로 Jetty를 사용함), GWT 플러그인 및 Hibernate와 관련이있는 것으로 보입니다 (물론 다른 라이브러리와 마찬가지로).

    그것은 Hibernate Bug Report에서 언급 된 버그와 비슷하지만 우리의 경우 GWT 플러그인을 통해 실행 중이며 ConnectionProvider에 ClassCastException이 발생합니다.

    버그 보고서에 언급 된 수정 사항으로 인해 특정 문제가 해결됩니다.

    org.hibernate.service.classloading.internalClassLoaderServiceImpl의 경우 생성자를 통해 부모를 null로 설정합니다.

    this.classClassLoader = new ClassLoader(null) {
            @Override
            protected Class<?> findClass(String name) throws ClassNotFoundException {
                for ( ClassLoader loader : classLoadingClassLoaders ) {
                    try {
                        return loader.loadClass( name );
                    }
                    catch (Exception ignore) {
                    }
                }
                throw new ClassNotFoundException( "Could not load requested class : " + name );
            }
    };
    
  2. ==============================

    2.이미있는 경우 / lib 디렉토리에서 ejb3-persistence.jar을 제거하십시오. 그것은 hibernate-jpa-2.0-api-1.0.1.Final.jar과 충돌한다. 이것은이 문제를 가지고 나에게 도움이되었는데, 나는 Ghost, Ghost, Hibernate 4, Spring 3.1.1을 Openshift 환경 https에 호스트했다. : //openshift.redhat.com/app/

    이미있는 경우 / lib 디렉토리에서 ejb3-persistence.jar을 제거하십시오. 그것은 hibernate-jpa-2.0-api-1.0.1.Final.jar과 충돌한다. 이것은이 문제를 가지고 나에게 도움이되었는데, 나는 Ghost, Ghost, Hibernate 4, Spring 3.1.1을 Openshift 환경 https에 호스트했다. : //openshift.redhat.com/app/

  3. ==============================

    3.persistence.xml에서 org.hibernate.ejb.HibernatePersistence 를 설정할 필요가 없다고 생각합니다. 문서를 확인하십시오.

    persistence.xml에서 org.hibernate.ejb.HibernatePersistence 를 설정할 필요가 없다고 생각합니다. 문서를 확인하십시오.

  4. from https://stackoverflow.com/questions/8891467/exception-in-gwt-dev-mode-spring-3-1-hibernate-4-0-1 by cc-by-sa and MIT license