james
james

Reputation: 1845

Spring Data JPA Java Config HibernatePersistence.class

HibernatePersistence.class is deprecated. What should be the alternative for this code?

import org.hibernate.ejb.HibernatePersistence
@Bean  
        public LocalContainerEntityManagerFactoryBean entityManagerFactory() {  
                LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();  
                entityManagerFactoryBean.setDataSource(dataSource());  
                entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistence.class);  
                entityManagerFactoryBean.setPackagesToScan(env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));  

                entityManagerFactoryBean.setJpaProperties(hibProperties());  

                return entityManagerFactoryBean;  
        } 

Upvotes: 5

Views: 5978

Answers (3)

Max Gabderakhmanov
Max Gabderakhmanov

Reputation: 922

I also had this problem. I've fixed it by adding following dependency to pom.xml:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.0.2.Final</version>
</dependency>

plus

import org.hibernate.ejb.HibernatePersistence;

Upvotes: 0

M. Nashath
M. Nashath

Reputation: 117

Your code is perfectly alright. You don't need any alternative solutions. The issue is because of you missed the hibernate entity manager .jar library [or hibernate-entitymanager maven dependency if your using maven as your project builder]. Add hibernate-entitymanager maven dependency inside your pom file and update your project. It's work fine.

Thank you. Mohamed Nashath.

Upvotes: 0

Koitoer
Koitoer

Reputation: 19533

It should be.

org.hibernate.jpa.HibernatePersistenceProvider

As the provider

http://docs.jboss.org/hibernate/orm/4.3/javadocs/

Upvotes: 9

Related Questions