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
According to this maven repository information, your used
spring-orm verionof5.3.19comes withspring-data-jpaof version2.6.4which then is bundled with the dependency ofhibernate-corewhere the supported version to be used is5.6.0.Final.Also according to the spring documentation
So according to that maven repo documentation and spring documentation the version that should be used is
hibernate-core5.6.0.Final.Keep in mind that java is backwards compatible, which means that a project compiled with a previous
JDKwill most times be able to run in a newerJDKexcept 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-core5.6.0.Final, according to which you should not expect any problems withJDK 11.