30

when you use spring & Hibernate, have you ever met a log warning that says

WARN o.hibernate.ejb.HibernatePersistence - HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.

How to handle that? Thank you for any answer.

5
  • 5
    use [org.hibernate.jpa.HibernatePersistenceProvider] instead ? Commented Feb 19, 2014 at 22:02
  • 1
    It's a Hibernate bug. Supposedly fixed in newer versions: hibernate.atlassian.net/browse/HHH-8625 Commented Feb 26, 2014 at 9:27
  • Not fixed in latest stable. Commented Mar 5, 2014 at 19:29
  • I get this in 4.3.4.Final. Bootstrapping with Persistence.createEntityManagerFactory("Foo") and nothing else. Commented Mar 25, 2014 at 0:14
  • 5
    It still a bug in 4.3.5, see hibernate.atlassian.net/browse/HHH-9141 Commented Jun 6, 2014 at 7:22

8 Answers 8

34

It should be

org.hibernate.jpa.HibernatePersistenceProvider 

Have a look at this.

Deprecated.

Use HibernatePersistenceProvider instead

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

2 Comments

cause of the problem? how to fix the problem? What files should I change in spring configuration?
@riship89 You have to change the persistence.xml. @AaronHall Thats wrong. I wrote to use org.hibernate.jpa.HibernatePersistenceProvider instead of javax.persistence.spi.PersistenceProvider.
15

If you are working with Spring Data JPA and Java Configuration, you will be able to solve it, adding the following code in your Entity Manager Factory:

factory.setPersistenceProvider(new HibernatePersistenceProvider());

@Bean public EntityManagerFactory entityManagerFactory() throws SQLException { HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); vendorAdapter.setGenerateDdl(true); vendorAdapter.setShowSql(true); LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setJpaVendorAdapter(vendorAdapter); **factory.setPersistenceProvider(new HibernatePersistenceProvider());** factory.setPackagesToScan("com.company.appname.persistence.domain"); factory.setDataSource(dataSource()); factory.setJpaProperties(hibernateProperties()); factory.afterPropertiesSet(); return factory.getObject(); } 

You will find a good example of Hibernate configuration with Spring Data JPA here: http://spring.io/guides/tutorials/data/3/

Comments

9

For users who are not using SPRING:

We can replace the standard javax.persistence bootstrapping by a Hibernate specific one.

Old:

EntityManagerFactory emf = Persistence.createEntityManagerFactory( PERSISTENCE_UNIT, props ); 

New:

PersistenceProvider provider = new HibernatePersistenceProvider(); EntityManagerFactory emf = provider.createEntityManagerFactory( PERSISTENCE_UNIT, props); 

The deprecated warnings should now be gone. The problem was still present in 4.3.1.Final. In 5.1.0.Final it should be fixed.

2 Comments

:( too bad. Can't go to 5.1, it breaks all my naming strategies, and there's no funding for spending hours and hours messing with naming strategies...
I'm using Hibernate 4.3.8.Final and warnings are still there. However I managed to fix the issue with the suggested change in persistence.xml, plus the change recommended by this answer. I don't see the warnings anymore
8

Had this problem while working with JPA's Entity Manager in Spring context, having transaction-type="RESOURCE_LOCAL" in persistence.xml.

It's not always a bug. I actually had the wrong provider configured.

I just changed the provider in persistence.xml from

<provider>org.hibernate.ejb.HibernatePersistence</provider> 

to

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> 

and it works fine.

Notice that the package changed from EJB to JPA

1 Comment

Please stop commenting that it doesn't work for you. I didn't said my comment is always a solution. It is a solution sometimes. My comment was just a heads up for checking this, and I thought it may be handy. As I said : "It's not always a bug. I actually had the wrong provider configured." Maybe it's a common mistake.
2

You get this message because the class org.hibernate.ejb.HibernatePersistence is deprecated. Under my persistence.xml file I found the provider class had org.hibernate.ejb.HibernatePersistence and I changed it to org.hibernate.jpa.HibernatePersistenceProvider as mentioned in the stacktrace warning message.

persistence.xml

<persistence-unit name="personPersistenceUnit" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <class>Person</class> <properties> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/db_name"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" /> .... </properties> </persistence-unit> 

1 Comment

For those in xml spring configuration see : stackoverflow.com/questions/24520602/… . The declaration is <property name="persistenceProvider"> <bean class="org.hibernate.jpa.HibernatePersistenceProvider"></bean> </property>
1

After changing your org.hibernate.ejb.HibernatePersistence to org.hibernate.jpa.HibernatePersistenceProvider in the persistence.xml Change also the hibernate-entitymanager dependency version, get the last version 5.2.10.Final that fixed the bug. Here is:

http://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager/5.2.10.Final

it's worked for me

1 Comment

For sure it will work for all versions greater then 5.x.x.
0

I changed the reference to:

org.hibernate.jpa.HibernatePersistenceProvider 

but it didn't work.

Then I removed all the references to Hibernate 4.x jar libs, downloaded last version (5.2.7), then added this jar files and it finally works.

Comments

0

If you are creating a Has-A relationship and forgot to mention @Embedded then it will throw the same error.

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named TEST at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54) 

1 Comment

Can you elaborate more? Do mean the issue is at the Entity level?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.