After updating my project from Spring Boot Version 3.2.0 to 3.2.1, I am no longer able to start my application.
My application uses Spring JPA (via spring-boot-starter-data-jpa
) and a MySQL 8.2 database.
During start-up, I receive the following error message:
[ERROR] 2023-12-22 10:44:44 SpringApplication - Application run failed
java.lang.ClassNotFoundException: org.hibernate.dialect.MySQL57Dialect
at java.base/java.net.URLClassLoader.findClass(Unknown Source) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(Unknown Source) ~[na:na]
at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.loadClass(JarUrlClassLoader.java:104) ~[XXX]
at org.springframework.boot.loader.launch.LaunchedClassLoader.loadClass(LaunchedClassLoader.java:91) ~[XXX]
at java.base/java.lang.ClassLoader.loadClass(Unknown Source) ~[na:na]
... 28 common frames omitted
Wrapped by: java.lang.NoClassDefFoundError: org/hibernate/dialect/MySQL57Dialect
at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.determineDatabaseDialectClass(HibernateJpaVendorAdapter.java:203) ~[spring-orm-6.1.2.jar!/:6.1.2]
at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.buildJpaPropertyMap(HibernateJpaVendorAdapter.java:148) ~[spring-orm-6.1.2.jar!/:6.1.2]
at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.getJpaPropertyMap(HibernateJpaVendorAdapter.java:132) ~[spring-orm-6.1.2.jar!/:6.1.2]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:365) ~[spring-orm-6.1.2.jar!/:6.1.2]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352) ~[spring-orm-6.1.2.jar!/:6.1.2]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.1.jar!/:3.2.1] [11 skipped]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) ~[spring-boot-3.2.1.jar!/:3.2.1]
... 21 common frames omitted
Wrapped by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [XXX/MySqlConfig.class]: org/hibernate/dialect/MySQL57Dialect
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.1.jar!/:3.2.1] [10 skipped]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) ~[spring-boot-3.2.1.jar!/:3.2.1]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:464) ~[spring-boot-3.2.1.jar!/:3.2.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:334) ~[spring-boot-3.2.1.jar!/:3.2.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1358) ~[spring-boot-3.2.1.jar!/:3.2.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1347) ~[spring-boot-3.2.1.jar!/:3.2.1]
at XXX.Main.main(Main.java:53) ~[!/:na]
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:91) ~[XXX] [2 skipped]
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53) ~[XXX]
at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58) ~[XXX]
I looks like Hibernate 6.4 removed the MySQL57Dialect
class (or at least moved it to the hibernate-community-dialects
artifact). When I set the property <hibernate.version>6.3.2.Final</hibernate.version>
in my pom.xml file, my application starts without errors.
I created a repository with a test case to reproduce this issue: https://github.com/HennyWilly/springboot321-hibernate64-bug
PS: This is my first issue, so I am not sure if this is the right repository or if I should have opened this issue inside the spring-framework repository.
Comment From: bclozel
Running your sample with Hibernate 6.3.2 shows the following:
[main] WARN org.hibernate.orm.deprecation -- HHH90000025: MySQL57Dialect does not need to be specified explicitly using 'hibernate.dialect' (remove the property setting and it will be selected by default)
[main] WARN org.hibernate.orm.deprecation -- HHH90000026: MySQL57Dialect has been deprecated; use org.hibernate.dialect.MySQLDialect instead
It seems Spring Framework is still referring to this class in HibernateJpaVendorAdapter
and does not handle Hibernate 6.4 compatibility on dialects. I'll transfer the issue to the Framework project for consideration.
Comment From: snicoll
Thanks for the report.
In the MainTests
you are creating the EMF manually, which disables some of Spring Boot's auto-configuration. For quite some time now, Spring Boot configures the JPA infrastructure so that the provider is responsible for looking up the proper dialect. By forcing the database platform to be MYSQL
you're opting out of that.
There are two ways to fix this. You can either remove the explicit platform in jpaVendorAdapter
, or you can fix the wrong dialect lookup by adding the following to the jpaVendorAdaptor
method:
hibernateJpaVendorAdapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
Arguably, the former is preferred as it is more in line with what the application does (let the JPA provider detect the infrastructure). We'll fix the MySQL dialect in the next maintenance release.
Comment From: barbetb
Thanks for the report.
In the
MainTests
you are creating the EMF manually, which disables some of Spring Boot's auto-configuration. For quite some time now, Spring Boot configures the JPA infrastructure so that the provider is responsible for looking up the proper dialect. By forcing the database platform to beMYSQL
you're opting out of that.There are two ways to fix this. You can either remove the explicit platform in
jpaVendorAdapter
, or you can fix the wrong dialect lookup by adding the following to thejpaVendorAdaptor
method:
java hibernateJpaVendorAdapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
Arguably, the former is preferred as it is more in line with what the application does (let the JPA provider detect the infrastructure). We'll fix the MySQL dialect in the next maintenance release.
This didn't resolve the problem for the Oracle12cDialect for me.
I have specified:
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: oracle.jdbc.OracleDriver
and
spring:
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.OracleDialect
I'm not creating any custom HibernateJpaVendorAdapter and I also don't see the warning bclozel posted.
I've also tried running without those properties, to no avail.
Comment From: snicoll
@barbetb the arrangement that you've quoted is quite specific so commenting with a different arrangement and stating "didn't resolve the problem" is not very helpful. The warning that Brian referenced is about MySQL for a start, and for an older Hibernate version.
All in all, this is confusing and you probably want to ask for support on StackOverflow first. If you believe you've found a different bug, then a separate issue is needed with a small sample that demonstrates the problem you're experiencing.
Comment From: barbetb
@snicoll my apologies. I got a bit confused with all the tickets opened for this issue.
I had the same issue as https://github.com/spring-projects/spring-framework/issues/31892 and that issue refered to this one. I now see you made fix for the oracle one here https://github.com/spring-projects/spring-framework/commit/03907095776eadf67a04dbaf62ffb3fe32125232 , but it hasn't been released yet.