Spring JPA 5.0.6:找不到org / hibernate / ejb / HibernatePersistence

时间:2018-06-13 06:31:47

标签: java spring hibernate spring-data-jpa

(我知道之前已经问过这个问题,但是从来没有问过Spring 5.x)

我刚刚选择了一个大型的Spring应用程序,并完成了从Spring 3.2.16升级到5.0.6的任务。作为其中的一部分,我也将OpenJpa更改为Hibernate,因为Spring不再支持OpenJPA(并且版本3尚未发布,所以看起来如此)。

所以,我的依赖是

  • Spring 5.0.6.RELEASE
  • hibernate-jpa-2.1-api 1.0.0.Final
  • hibernate-core 5.3.1.Final

我收到以下异常:

Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence
        at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:101)
        at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1452)

配置看起来像

    <bean id="ums.entityManagerFactory" 
          class="com.company.package.HibernateJPAEntityManagerFactoryBean"
          destroy-method="destroy">
        <property name="dataSource" ref="persistenceDataSource" />
        <property name="persistenceUnitName" value="ums"/>
        <property name="persistenceXmlLocation" value="classpath:META-INF/ums-persistence.xml" />
    </bean>

<bean id="persistenceDataSource" 
      class="com.company.package.AutoDriverBasicDataSource">
    <property name="url" value="jdbc:h2:data/persistence/persistence" />
    <property name="username" value="<username>" />
    <property name="password" value="<password>" />
</bean>

在entiyManager的setDataSource中,我们设置了一个 new HibernateJpaDialect()和new HibernateJpaVendorAdapter()

hibernate-core 依赖项包含 org.hibernate.ejb 但没有类 HibernatePersistence

0 个答案:

没有答案