我正在尝试配置没有persisten.xml文件的LocalContainerEntityManagerFactoryBean。
这是我的dataSource - 它适用于Hibernate SessionFactory - 所以,没关系。
<bean id="dataSource"
class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/test"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
这是我的LocalContainerEntityManagerFactoryBean
<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="application.models" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property>
</bean>
我得到的例外情况:
...Could not instantiate bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Failed to determine Hibernate PersistenceProvider
我阅读了文档,我知道LocalContainerEntityManagerFactoryBean具有这样的属性,类似的创建LocalContainerEntityManagerFactoryBean的样式在Spring in Action 3中工作,在这里:http://softwarecave.org/2014/03/15/using-jpa-and-jta-with-spring/
也许你知道我做错了什么,或者至少春天想通过这个例外告诉我什么?
提前致谢, 干杯:)
PS要清楚,未能确定Hibernate PersistenceProvider并不意味着spring期望persistence.xml - 这应该是错误的:没有从{classpath *:META-INF / persistence.xml}解析持久性单元
解决:
感谢JB Nizet - 如果你有类似的问题补充:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.6.Final</version>
</dependency>
到pom.xml
答案 0 :(得分:1)
下面的代码适合我。 的 强>
<强>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="dataSource">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
</bean>
</property>
</bean>
强> <强> 强>
使用hibernate = 4.3.5.Final 弹簧= 4.1.4.RELEASE