I am trying to configure LocalContainerEntityManagerFactoryBean without persisten.xml file.
this is my dataSource - it works for Hibernate SessionFactory - so, it is ok.
<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>
this is my 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>
An exception that i am getting:
...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
I read documentation, and i know that LocalContainerEntityManagerFactoryBean has such property, and similar style of creating LocalContainerEntityManagerFactoryBean works in Spring in Action 3 and here: http://softwarecave.org/2014/03/15/using-jpa-and-jta-with-spring/
Maybe You have an idea what i am doing wrong or at least what spring want tell me via this exception ?
Thanks in advance, Cheers :)
P.S to be clear, Failed to determine Hibernate PersistenceProvider doesn't mean that spring expect persistence.xml - this should be error like: No persistence units parsed from {classpath*:META-INF/persistence.xml}
RESOLVED:
thanks JB Nizet - if You will have similar problem add:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.6.Final</version>
</dependency>
to pom.xml
Below code works for me.
<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>
With hibernate = 4.3.5.Final spring=4.1.4.RELEASE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With