5

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;  
        } 

3 Answers 3

9

It should be.

org.hibernate.jpa.HibernatePersistenceProvider

As the provider

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

Sign up to request clarification or add additional context in comments.

5 Comments

that's my current provider.
And where in the api said that it is deprecated, why version of hibernate are you usgin _
<hibernate.version>4.3.1.Final</hibernate.version>
Update in my answer, it should be the jpa package according to the documentation, very weird that in final version hibernate deprecate it . Try a shoot using the org.hibernate.jpa.HibernatePersistenceProvider
Hey.. what is the xml version of above LocalContainerEntityManagerFactoryBean. I want to know how I can set persistence provider using xml inside my LocalContainerEntityManagerFactoryBean.
0

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.

Comments

0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.