Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

Hibernate cannot resolve org.hibernate.dialect.MySQL5Dialect as a strategy

ErrorUnable to resolve name [org.hibernate.dialect.MySQL5Dialect] as strategy [org.hibernate.dialect.Dialect]

Short answer

Hibernate 6 stopped using version-specific dialects such as MySQL5Dialect. Dialects now detect the database version themselves, and the legacy classes left the main module. Remove the dialect setting so Hibernate detects MySQL, or name org.hibernate.dialect.MySQLDialect. Only a very old MySQL needs the community dialect package.

  • Applies to Hibernate 6, Spring Boot 3, MySQL 8
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find every place the dialect class name is set: Spring properties, hibernate.cfg.xml, persistence.xml or Java config.

    grep -rn "MySQL5Dialect\|hibernate.dialect\|database-platform" src/ pom.xml build.gradle* 2>/dev/null
  2. 2Match what you see, then jump to its fix

    1. 1The class name in the message is MySQL5Dialect, MySQL57Dialect or similar, after an upgrade to Hibernate 6.A version-specific dialect name is still configuredFix
    2. 2You set the dialect only because older tutorials did.The setting is not needed at allFix
    3. 3The error stays after the change, and the server is MySQL older than 5.7.The database is older than Hibernate supportsFix

What does the error look like?

  • Unable to resolve name [org.hibernate.dialect.MySQL5Dialect] as strategy [org.hibernate.dialect.Dialect]

Cause 1 of 3

A version-specific dialect name is still configured

1Check

The Hibernate 6.0 migration guide says version-specific dialects are deprecated because dialects detect and adapt to the database version. Its list of dialects to use instead includes org.hibernate.dialect.MySQLDialect.

grep -rn "MySQL[0-9]*Dialect" src/

2Fix

Replace the old name with MySQLDialect. In Spring Boot the setting is spring.jpa.database-platform; a raw Hibernate property goes under spring.jpa.properties.

# application.properties
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
# or the pass-through form
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect

3Verify

Start the application; the SessionFactory builds without the strategy error.

./gradlew bootRun

Confirmed by docs.hibernate.org

Did this fix it?

Cause 2 of 3

The setting is not needed at all

1Check

The Spring Boot how-to says the JPA provider detects the dialect automatically, and that spring.jpa.database-platform is only for setting one yourself.

grep -rn "dialect\|database-platform" src/main/resources/

2Fix

Delete the dialect line and let Hibernate pick it from the JDBC connection.

# application.properties: remove these lines
# spring.jpa.database-platform=...
# spring.jpa.properties.hibernate.dialect=...

3Verify

The application starts and queries run against MySQL.

./gradlew bootRun

Confirmed by docs.spring.io

Did this fix it?

Cause 3 of 3

The database is older than Hibernate supports

1Check

The Hibernate 6.2 migration guide lists 5.7 as the minimum MySQL version. Legacy dialect code for unsupported versions moved out of hibernate-core into the hibernate-community-dialects module, under the org.hibernate.community.dialect package.

mysql --version

2Fix

Upgrade the database to a supported version. If you cannot, add the hibernate-community-dialects module at the same version as Hibernate and use the matching class from the org.hibernate.community.dialect package.

// build.gradle: same version as hibernate-core
implementation 'org.hibernate.orm:hibernate-community-dialects:<hibernate-version>'

3Verify

The class resolves and the application starts.

./gradlew dependencies --configuration runtimeClasspath | grep hibernate

Confirmed by docs.hibernate.org

Did this fix it?

How do I stop it coming back?

  • Do not name a database version in the dialect; use the plain dialect or none.
  • Read the migration guide of the Hibernate version a Spring Boot upgrade brings.
  • Search the whole repository, including test resources, for old dialect names after an upgrade.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.