-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Description
Whilst trying to upgrade our application to use Spring Boot 2.1.0 I hit upon a problem when Hibernate initialises. We are currently tied to using Hibernate 5.2.x and so far as I can tell Spring Boot 2.1.0 should still support this version. However, there appears to be an explicit dependency on Hibernate 5.3.x during the Spring Boot JPA auto-configuration. With Hibernate 5.2.x when the HibernateJpaConfiguration
class executes to bootstrap Hibernate, a ClassNotFoundException
is thrown as it's unable to locate the new to Hibernate 5.3.x class BeanContainer.
Caused by: java.lang.ClassNotFoundException: org.hibernate.resource.beans.container.spi.BeanContainer
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 45 common frames omitted
The problem looks to be in the HibernateJpaConfiguration.determineHibernatePropertiesCustomizers
method where it instantiates a SpringBeanContainer
.
I have attached a super simple project generated from the Spring Initializr that demonstrates the problem. The only change I made following project creation was to set the property hibernate.version
to be 5.2.17.Final
. Simply run the Maven build or start up the app to see the problem.
Having taken a look at the sources, there appears to be no conditional check during initialization to establish whether the BeanContainer
class is available. I think we need something similar to what can be found in LocalSessionFactoryBean
@Override
public void setBeanFactory(BeanFactory beanFactory) {
if (beanFactory instanceof ConfigurableListableBeanFactory &&
ClassUtils.isPresent("org.hibernate.resource.beans.container.spi.BeanContainer",
getClass().getClassLoader())) {
this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
}
}