74

Is there a Hibernate dialect for MySQL 8? Or should I use the org.hibernate.dialect.MySQL57Dialect that ships with Hibernate? I'm using hibernate 5.2.16

unknow
  • 869
  • 1
  • 7
  • 10

11 Answers11

109

MySQL8Dialect(org.hibernate.dialect.MySQL8Dialect) is available in hibernate bundle 5.3.1.Final. You can use:

org.hibernate.dialect.MySQL8Dialect
crispengari
  • 7,901
  • 7
  • 45
  • 53
Vipin Purohit
  • 1,099
  • 1
  • 7
  • 7
  • 2
    Awesome... spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect worked perfectly for me - HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect. Wondering why this is not accepted yet? May be I am using Hibernate 5.3.7 with Springboot 2.1.2. – Ajay Kumar Feb 05 '19 at 18:46
  • Is there a way I can use this dialect in hibernate 4.1.10 ? I am on java 1.7 right now and looks like I need to upgrade to java 1.8 in order to use hibernate 5.3.1 which is big issue for me . Any help ? – Naxi Mar 30 '19 at 11:22
  • 1
    "MySQL8Dialect has been deprecated; use org.hibernate.dialect.MySQLDialect instead" – Rômulo Sorato Aug 23 '22 at 17:20
28

yes, For MySQL8, use org.hibernate.dialect.MySQL8Dialect

duliu1990
  • 359
  • 4
  • 6
23

If you are using Gradle (e.g. for Grails) just configure:

in application.yml

dataSource:
...
    driverClassName: com.mysql.cj.jdbc.Driver
    dialect: org.hibernate.dialect.MySQL8Dialect
....

in build.gradle

dependencies {
    ...
    runtime 'mysql:mysql-connector-java:8.0.17'
    ...

Pay attention on mysql-connector version and non-deprecated driver class name

Eugene Hoza
  • 621
  • 1
  • 6
  • 19
11
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
spring.jpa.properties.hibernate.dialect.storage_engine=innodb

got from here

Gregory Iyama
  • 139
  • 1
  • 3
4

I know this question is a couple of weeks old, but for completeness it appears Hibernate 5.3 does have a MySQL8 dialect

https://docs.jboss.org/hibernate/orm/5.3/javadocs/org/hibernate/dialect/package-summary.html

I have not used it, so I cannot comment on its quality, but the support appears to be there.

MaxPower
  • 881
  • 1
  • 8
  • 25
  • 1
    I try it, there is error `Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]` ,mysql version is 8. hibernate version is 5.0.1. I revert it to `MySQL57Dialect` is work fine – 袁文涛 Jun 21 '18 at 03:13
  • 1
    Can’t speak to much, but unless there’s a typo in your version number of Hibernate, that would be my first guess. It requires at least 5.3 – MaxPower Jun 21 '18 at 03:30
4

Since Hibernate 6, org.hibernate.dialect.MySQL8Dialect is deprecated. And now it is recommended to use org.hibernate.dialect.MySQLDialect. See Hibernate JavaDoc for reference

3

Yes, MySQL8Dialect for MySql 8. In my case I have used MySQL8Dialect for MySql 8 in my spring boot application by following way:

spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect  
Tibebes. M
  • 6,940
  • 5
  • 15
  • 36
3

If you are using SpringBoot

spring:
  jpa:
    hibernate:
      ddl-auto: update
    database-platform: org.hibernate.dialect.MySQL8Dialect
Abderrazzak Nejeoui
  • 1,496
  • 12
  • 9
1

Looking over at MySQL 8's release notes, MySQL 8.x has been in development and has only been out for GA since 2018-04-19 (less than a month ago), so I doubt there would be a dialect already made specifically for it.

You can see a list of all hibernate dialects here, and as you can see, there is no MySQL 8 dialect.

MySQLDialect should only be used for MySQL 5 and earlier whereas MySQL57Dialect should be used for MySQL 5.x as well as 8.x for now.

TwiN
  • 3,554
  • 1
  • 20
  • 31
  • 2
    there is ' MySQL8Dialect ' ,you can check it .https://docs.jboss.org/hibernate/orm/5.3/javadocs/org/hibernate/dialect/MySQL8Dialect.html – 袁文涛 Jun 21 '18 at 02:50
1

I was able to resolve this by simply adding the configuration below to my application.properties file.

#Hibernate

spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL8Dialect

spring.jpa.driverClassName= com.mysql.cj.jdbc.Driver 
m4n0
  • 29,823
  • 27
  • 76
  • 89
stephen
  • 31
  • 1
0

I had the similar query as I installed MySQL 8 Server and tried to interact with the same using my Spring Boot Application.

But I was unable to do so.

When I explored the Source Code of MySQL5Dialect class, it's documentation clearly mentions that this dialect class has been dedicated to MySQL 5.X versions.

I am not sure whether it supports MySQL 8.X versions.

Thus I would suggest to use MySQL 5.X till an official dialect is released with Hibernate.