Java MySQL 8 的休眠方言?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50322550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 23:33:55  来源:igfitidea点击:

Hibernate dialect for MySQL 8?

javamysqlhibernate

提问by unknow

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

MySQL 8 有 Hibernate 方言吗?或者我应该使用 Hibernate 附带的 org.hibernate.dialect.MySQL57Dialect 吗?我正在使用休眠 5.2.16

回答by TwiN

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.

查看MySQL 8 的发行说明,MySQL 8.x 一直在开发中,并且自 2018 年 4 月 19 日(不到一个月前)以来才用于 GA,所以我怀疑是否已经有专门为它制作的方言.

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

您可以在此处查看所有 hibernate 方言的列表,并且如您所见,没有 MySQL 8 方言。

MySQLDialectshould only be used for MySQL 5 and earlier whereas MySQL57Dialectshould be used for MySQL 5.x as well as 8.x for now.

MySQLDialect应该只用于 MySQL 5 及更早版本,而现在MySQL57Dialect应该用于 MySQL 5.x 和 8.x。

回答by Philip Dilip

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

我在安装 MySQL 8 Server 时遇到了类似的查询,并尝试使用 Spring Boot 应用程序与之交互。

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.

当我探索 MySQL5Dialect 类的源代码时,它的文档清楚地提到这个方言类专用于 MySQL 5.X 版本。

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

我不确定它是否支持 MySQL 8.X 版本。

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

因此,我建议在 Hibernate 发布官方方言之前使用 MySQL 5.X。

回答by MaxPower

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

我知道这个问题已经有几个星期了,但为了完整起见,Hibernate 5.3 确实有 MySQL8 方言

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

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.

我没有用过它,所以我不能评论它的质量,但支持似乎在那里。

回答by Vipin Purohit

MySQL8Dialect(org.hibernate.dialect.MySQL8Dialect) is available in hibernate bundle 5.3.1.Final. you can use that.

MySQL8Dialect(org.hibernate.dialect.MySQL8Dialect) 在 hibernate bundle 5.3.1.Final 中可用。你可以使用它。

回答by duliu1990

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

是的,对于 MySQL8,使用 org.hibernate.dialect.MySQL8Dialect

回答by Eugene Hoza

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

如果您使用 Gradle(例如 Grails),只需配置:

in application.yml

在 application.yml 中

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

in build.gradle

在 build.gradle 中

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

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

注意 mysql-connector 版本和非弃用的驱动程序类名