Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to determine Hibernate PersistenceProvider

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

like image 491
bkowalczyyk Avatar asked Oct 04 '14 11:10

bkowalczyyk


1 Answers

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

like image 180
user3069716 Avatar answered Nov 13 '22 14:11

user3069716