Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassNotFoundException: org.hibernate.dialect.MySQL57Dialect with Hibernate 6.4 #31889

Closed
HennyWilly opened this issue Dec 22, 2023 · 5 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug
Milestone

Comments

@HennyWilly
Copy link

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 22, 2023
@bclozel
Copy link
Member

bclozel commented Dec 22, 2023

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.

@bclozel bclozel transferred this issue from spring-projects/spring-boot Dec 22, 2023
@bclozel bclozel changed the title (Spring Boot 3.2.1) ClassNotFoundException: org.hibernate.dialect.MySQL57Dialect ClassNotFoundException: org.hibernate.dialect.MySQL57Dialect with Hibernate 6.4 Dec 22, 2023
@bclozel bclozel added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Dec 22, 2023
@snicoll snicoll self-assigned this Dec 22, 2023
@snicoll
Copy link
Member

snicoll commented Dec 22, 2023

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.

@barbetb
Copy link

barbetb commented Jan 9, 2024

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.

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.

@snicoll
Copy link
Member

snicoll commented Jan 9, 2024

@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.

@barbetb
Copy link

barbetb commented Jan 9, 2024

@snicoll my apologies. I got a bit confused with all the tickets opened for this issue.

I had the same issue as #31892 and that issue refered to this one. I now see you made fix for the oracle one here 0390709 , but it hasn't been released yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants