Simultaneous use of Hibernate and Spring data jpa?

You need a single way of configuration you are now configuring both Hibernate and JPA. You should be using JPA for configuration so remove the hibernate setup.

You are using Hibernate4 so you can take advantage of the, not so well known, HibernateJpaSessionFactoryBean of Spring. If you need access to the SessionFactory (which I assume you need).

When applied your configuration will like something like this.

<bean id="sessionFactory" class="org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="entityManagerFactory"/>
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
    </property>
</bean>

I would suggest to only use this as an intermediate solution while you are refactoring your applicaiton to use the plain JPA api. I wouldn't suggest mixing both strategies.


Instead of creating a SessionFactory, use EntityManager.unwrap(Session.class) to get a Hibernate Session and retrieve the session factory from the Session object.

You can also use EntityManagerFactory.unwrap(SessionFactory.class) to get the Hibernate SessionFactory directly.