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.
It should be
org.hibernate.jpa.HibernatePersistenceProvider
Have a look at this.
Deprecated.
Use HibernatePersistenceProvider instead
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/
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With