spring maven project upgrade to 11

796 Views Asked by At

I have a maven java project. The SDK was java 8, now i want to upgrade to java 11. I also want to upgrade all the dependencies to the latest ones. It is a spring project (not spring-boot!!)

I could resolve all different upgrade issues, however there is an error in entity manager factory to set the persistence provider class.

  @Bean(name = "entityManagerFactory")
  @DependsOn("flyway")
  public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() throws ClassNotFoundException {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setPackagesToScan(environment.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));
    entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
...
}

the HibernatePersistenceProvider.class implements the jakarta.persistence.spi.PersistenceProvider

however the setPersistenceProviderClass method requires a class of javax.persistence.spi.PersistenceProvider

i have

<org.springframework.version>5.3.19</org.springframework.version>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-orm</artifactId>
  <version>${org.springframework.version}</version>
</dependency>
<dependency>
  <groupId>org.hibernate.orm</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>6.0.0.Final</version>
</dependency>

there is one more strange thing to me. in IntelliJ when i open the class of AbstractEntityManagerFactoryBean it says bytecode version is java 8, but HibernatePersistenceProvider is java 11

1

There are 1 best solutions below

2
Panagiotis Bougioukos On

According to this maven repository information, your used

spring-orm verion of 5.3.19 comes with spring-data-jpa of version 2.6.4 which then is bundled with the dependency of hibernate-core where the supported version to be used is 5.6.0.Final.

Also according to the spring documentation

Version 5.3.19

As of Spring Framework 5.1, Spring requires JDK 8+ (Java SE 8+) and provides out-of-the-box support for JDK 11 LTS

So according to that maven repo documentation and spring documentation the version that should be used is hibernate-core 5.6.0.Final.

Keep in mind that java is backwards compatible, which means that a project compiled with a previous JDK will most times be able to run in a newer JDK except when some structural components have been affected and for that reason you need to inspect the oracle migration documentation to see where you stand.

But for the specific issue that you mention here and your concern I would go with the documentation which mentions to use the hibernate-core 5.6.0.Final, according to which you should not expect any problems with JDK 11.