Encountered a deprecated javax.persistence.spi.PersistenceProvider

前端 未结 7 706
甜味超标
甜味超标 2020-12-03 06:40

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

WARN o.hibernate.ejb.HibernatePersistence - HHH015016: Encountered a

7条回答
  •  天命终不由人
    2020-12-03 07:16

    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/

提交回复
热议问题