从JBoss AS 7.1.1迁移到EAP 6.2时,加载时弹簧定义的entityManagerFactory会失败

时间:2014-05-08 15:36:07

标签: spring jpa jboss

我正在使用带有spring 4.0.2的JPA 2.1开发一个应用程序。 Jboss服务器提供JNDI数据源。

我在services.xml中定义了这个entityManager,以避免使用persistence.xml文件:

<jee:jndi-lookup id="projectDataSourceTaget" jndi-name="${jndi.datasourceName}"
    expected-type="javax.sql.DataSource" />
 <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    depends-on="flyway">
    <property name="jpaVendorAdapter">
      <bean
        class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    </property>
    <property name="packagesToScan" value="com.xxx" />
    <property name="persistenceUnitName" value="projectEntityManager" />
    <property name="jtaDataSource" ref="projectDataSourceTaget" />
    <property name="jpaProperties">
      <props>
        <prop key="hibernate.transaction.manager_lookup_class">
          org.hibernate.transaction.JBossTransactionManagerLookup
        </prop>
        <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
        <!-- validate | update | create | create-drop -->
        <prop key="hibernate.hbm2ddl.auto">validate</prop>
        <prop key="hibernate.show_sql">true</prop>
        <prop key="hibernate.format_sql">false</prop>
        <prop key="org.hibernate.envers.use_revision_entity_with_native_id">false</prop>
        <prop key="javax.persistence.transactionType">JTA</prop>
      </props>
    </property>
  </bean>

虽然在更改为EAP 6.2时,这在Jboss 7.1.1中运行良好但是无法初始化服务:

17:27:17,061 WARN  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (ServerService Thread Pool -- 48) HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
17:27:17,079 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 48) MSC000001: Failed to start service jboss.persistenceunit."Project.war#Project": org.jboss.msc.service.StartException in service jboss.persistenceunit."Project.war#Project": javax.persistence.PersistenceException: [PersistenceUnit: Project] Unable to build EntityManagerFactory
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:103) [jboss-as-jpa-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_60-ea]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_60-ea]
    at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_60-ea]
    at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final-redhat-1.jar:2.1.1.Final-redhat-1]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: GaIA] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:76)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:200) [jboss-as-jpa-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$600(PersistenceUnitServiceImpl.java:57) [jboss-as-jpa-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:99) [jboss-as-jpa-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    ... 4 more
Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
    at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:98)
    at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:68)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:174)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:76)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:160)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:132)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1822)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1780)
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
    ... 9 more
我正在做什么?我在这个配置中尝试了几处更改,但似乎没有任何效果。也许在JBoss EAP 6.2上不支持LocalContainerEntityManagerFactoryBean?

1 个答案:

答案 0 :(得分:2)

最后我遇到了问题:在项目的旧版本中,定义了一个persistence.xml,已经在JBoss中部署了好几天,即使进行了干净部署(我猜这是因为文件系统出现故障)。这使得JBoss加载器搞砸了persistence.xml和services.xml中定义的entityManagers。