Java Hibernate 的 MariaDB 方言类名称是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37066024/
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-11 18:58:19  来源:igfitidea点击:

What is the MariaDB dialect class name for Hibernate?

javadatabasehibernatemariadb

提问by Bijaya Bhaskar Swain

In HibenateI am using MariaDBbut I couldn't find the dialect class name of MariaDB.

Hibenate 中,我使用的是MariaDB但我找不到MariaDB的方言类名称。

In Hibernate, MySQL5 dialect's name is

在 Hibernate 中,MySQL5 方言的名称是

<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

For Oracle 10g

对于 Oracle 10g

<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>

What is the dialect class name for MariaDB?

MariaDB的方言类名称是什么?

采纳答案by l00tr

As announced here, starting with Hibernate ORM 5.2.8 (around Feb 15, 2017), the dialects

正如这里宣布的,从 Hibernate ORM 5.2.8(2017 年 2 月 15 日左右)开始,方言

org.hibernate.dialect.MariaDB53Dialect

org.hibernate.dialect.MariaDB53Dialect

and

org.hibernate.dialect.MariaDBDialect

org.hibernate.dialect.MariaDBDialect

are available. The announcement concludes that

可用。该公告的结论是

If you are using MariaDB, it's best to use the MariaDB-specific Dialects from now on since it's much easier to match the MariaDB version with its appropriate Hibernate Dialect.

如果您正在使用 MariaDB,最好从现在开始使用 MariaDB 特定的方言,因为将 MariaDB 版本与其适当的 Hibernate 方言相匹配要容易得多。

回答by Jens

You should use the Mysql5Dialect, because MariaDB is 100% compatible with mysql.

您应该使用 Mysql5Dialect,因为 MariaDB 与 mysql 100% 兼容。

回答by maximilianus

From here, it was mentioned "it needs to be the MySQL5InnoDBDialect or MySQL57InnoDBDialect instead of the MySQLInnoDBDialect"

这里开始,有人提到“它需要是 MySQL5InnoDBDialect 或 MySQL57InnoDBDialect 而不是 MySQLInnoDBDialect”

For complete list, see http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#database-dialect

有关完整列表,请参阅 http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#database-dialect

New MariaDB dialect is added in 5.2.17. See JIRAand commit

5.2.17 中添加了新的 MariaDB 方言。查看JIRA提交

回答by Devabc

Very short answer

很简短的回答

The current dialects as of this writing are:

在撰写本文时,当前的方言是:

  • org.hibernate.dialect.MariaDB102Dialectfor MariaDB server 10.2
  • org.hibernate.dialect.MariaDB103Dialectfor MariaDB server 10.3 and later, provides sequence support.
  • org.hibernate.dialect.MariaDB10Dialectfor MariaDB server 10.0 and 10.1
  • org.hibernate.dialect.MariaDB53Dialectfor MariaDB server 5.3, and later 5.x versions.
  • org.hibernate.dialect.MariaDBDialectfor MariaDB server 5.1 and 5.2.
  • org.hibernate.方言。MariaDB102Dialectfor MariaDB 服务器10.2
  • org.hibernate.方言。MariaDB103Dialect用于 MariaDB 服务器10.3 及更高版本,提供序列支持。
  • org.hibernate.方言。MariaDB10Dialect用于 MariaDB 服务器10.0 和 10.1
  • org.hibernate.方言。MariaDB53Dialect用于 MariaDB 服务器5.3 和更高版本的 5.x 版本
  • org.hibernate.方言。MariaDBDialect用于 MariaDB 服务器5.1 和 5.2

Short answer

简答

When using a MariaDB server, you should use MariaDB Connector/J and MariaDB Hibernate dialects, not the MySQL ones. Even though MariaDB was created as a drop-in replacement and even though basic features will likely work when using the MySQL versions of those, subtle problems may occur or you may miss certain features.

使用 MariaDB 服务器时,您应该使用 MariaDB Connector/J 和 MariaDB Hibernate 方言,而不是 MySQL 方言。尽管 MariaDB 是作为替代品创建的,并且即使在使用 MySQL 版本时基本功能可能会起作用,也可能会出现细微的问题,或者您可能会错过某些功能。

A complete list of available MariaDB dialects are currently not mentioned in the Hibernate User Guide, but in the Hibernate JavaDoc. Depending on your MariaDB server version, you should select the corresponding dialect version. The current dialects as of this writing are:

可用的 MariaDB 方言的完整列表目前未在 Hibernate 用户指南中提及,但在Hibernate JavaDoc 中根据您的 MariaDB 服务器版本,您应该选择相应的方言版本。在撰写本文时,当前的方言是:

  • org.hibernate.dialect.MariaDB102Dialect for MariaDB server 10.2
  • org.hibernate.dialect.MariaDB103Dialect for MariaDB server 10.3 and later, provides sequence support.
  • org.hibernate.dialect.MariaDB10Dialect for MariaDB server 10.0 and 10.1
  • org.hibernate.dialect.MariaDB53Dialect for MariaDB server 5.3, and later 5.x versions.
  • org.hibernate.dialect.MariaDBDialect for MariaDB server 5.1 and 5.2.
  • org.hibernate.dialect.MariaDB102Dialect 用于 MariaDB 服务器 10.2
  • org.hibernate.dialect.MariaDB103Dialect 用于 MariaDB 服务器 10.3 及更高版本,提供序列支持。
  • org.hibernate.dialect.MariaDB10Dialect 用于 MariaDB 服务器 10.0 和 10.1
  • org.hibernate.dialect.MariaDB53Dialect 用于 MariaDB 服务器 5.3 和更高版本的 5.x 版本。
  • org.hibernate.dialect.MariaDBDialect 用于 MariaDB 服务器 5.1 和 5.2。

Note that for detailed usage information, you'll sometimes have to look in dialect source codes. (There are non-JavaDoc usage information comments in some dialect sources.)

请注意,有关详细的使用信息,您有时必须查看方言源代码。(某些方言来源中有非 JavaDoc 使用信息注释。)

If you want to change or explicitly mention the storage engine for the MariaDB dialect, you can use the storage_engineHibernate variable. For example: hibernate.dialect.storage_engine = innodb. IMO, you should do this explicitly, because the default can change when switching to a different MariaDB server version.

如果要更改或明确提及 MariaDB 方言的存储引擎,可以使用storage_engineHibernate 变量。例如:hibernate.dialect.storage_engine = innodb。IMO,您应该明确地执行此操作,因为切换到不同的 MariaDB 服务器版本时,默认值可能会更改。

If you're using a MariaDB server older than 10.1.2 (which doesn't support fractional seconds), then you may want to provide the parameter useFractionalSeconds=falseto the JDBC URL, otherwise MariaDB Connector/J will not truncate timestamps internally, which can cause time comparison problem when those values are using in comparison queries (even when using plain JDBC), which can cause Hibernate versioning problems and optimistic locking problems for temporal types.

如果您使用的 MariaDB 服务器早于 10.1.2(不支持小数秒),那么您可能需要将参数提供useFractionalSeconds=false给 JDBC URL,否则 MariaDB Connector/J 将不会在内部截断时间戳,这会导致在比较查询中使用这些值时(即使使用普通 JDBC 时)的时间比较问题,这可能导致 Hibernate 版本控制问题和时间类型的乐观锁定问题。

Long answer

长答案

The MariaDB dialect for Hibernate (5.3 as of this writing) is mentioned in the Hibernate User Guide. The mentioned dialect "short names" followed by remarks are:

Hibernate 用户指南中提到了Hibernate的 MariaDB 方言(撰写本文时为 5.3)。提到的方言“短名称”后跟注释是:

  • MariaDB: Support for the MariadB database. May work with newer versions

  • MariaDB53: Support for the MariadB database, version 5.3 and newer.

  • MariaDB:支持 MariaDB 数据库。可能适用于较新的版本

  • MariaDB53:支持 MariaDB 数据库,版本 5.3 和更新版本。

However, a complete list of the available official MariaDB dialects can be found in the Hibernate JavaDoc. Which currently lists:

但是,可以在Hibernate JavaDoc 中找到可用的官方 MariaDB 方言的完整列表。目前列出:

  • org.hibernate.dialect.MariaDB102Dialect for MariaDB server 10.2
  • org.hibernate.dialect.MariaDB103Dialect for MariaDB server 10.3 and later, provides sequence support.
  • org.hibernate.dialect.MariaDB10Dialect for MariaDB server 10.0 and 10.1
  • org.hibernate.dialect.MariaDB53Dialect for MariaDB server 5.3, and later 5.x versions.
  • org.hibernate.dialect.MariaDBDialect for MariaDB server 5.1 and 5.2.
  • org.hibernate.dialect.MariaDB102Dialect 用于 MariaDB 服务器 10.2
  • org.hibernate.dialect.MariaDB103Dialect 用于 MariaDB 服务器 10.3 及更高版本,提供序列支持。
  • org.hibernate.dialect.MariaDB10Dialect 用于 MariaDB 服务器 10.0 和 10.1
  • org.hibernate.dialect.MariaDB53Dialect 用于 MariaDB 服务器 5.3 和更高版本的 5.x 版本。
  • org.hibernate.dialect.MariaDBDialect 用于 MariaDB 服务器 5.1 和 5.2。

Each dialect successor inherits the settings from the previous dialect version. So the inheritance hierachy for MariaDB is: MariaDB103Dialect > MariaDB102Dialect > MariaDB10Dialect > MariaDB53Dialect > MariaDBDialect > MySQL5Dialect > MySQLDialect > Dialect

每个方言后继方言都继承了先前方言版本的设置。所以 MariaDB 的继承层次是:MariaDB103Dialect > MariaDB102Dialect > MariaDB10Dialect > MariaDB53Dialect > MariaDBDialect > MySQL5Dialect > MySQLDialect > Dialect

MariaDB was designed as a drop-in replacement for MySQL. But the databases are likely going to diverge as time goes by. Most basic features probably work without problems, allowing you to swap Connector/J clients (MariaDB client on MySQL server and vice versa), and allow you to swap dialects (MySQL dialect on MariaDB client and vice versa). But there are subtle differences that may cause unexpected problems. For example, the MySQL Connector/J client contains hardcoded checks for the server version, which will fail when using a MariaDB server, causing some features to be disabled in the client, such as the MySQL sendFractionalSeconds client parameter. This will cause fractional seconds to be disabled, so then the fractions will be truncated in the MySQL client but not in the MariaDB client. (This may even lead to optimistic locking problems when using versioning with date/time types in combination with non-max precision SQL date/time types. In these cases, use the max precision of 6.)

MariaDB 被设计为 MySQL 的替代品。但随着时间的推移,这些数据库很可能会发生分歧。大多数基本功能可能都没有问题,允许您交换 Connector/J 客户端(MySQL 服务器上的 MariaDB 客户端,反之亦然),并允许您交换方言(MariaDB 客户端上的 MySQL 方言,反之亦然)。但是有一些细微的差异可能会导致意想不到的问题。例如,MySQL Connector/J 客户端包含对服务器版本的硬编码检查,这在使用 MariaDB 服务器时会失败,导致客户端中的某些功能被禁用,例如 MySQL sendFractionalSeconds 客户端参数。这将导致小数秒被禁用,因此小数部分将在 MySQL 客户端中截断,但不会在 MariaDB 客户端中截断。

Also, the MariaDB dialect are expected to provide specific functionality for MariaDB: http://in.relation.to/2017/02/16/mariadb-dialects/

此外,MariaDB 方言有望为 MariaDB 提供特定功能:http: //in.relation.to/2017/02/16/mariadb-dialects/

In time, we will add new Dialects based on newer capabilities introduced by MariaDB.

...

If you are using MariaDB, it's best to use the MariaDB-specific Dialects from now on since it's much easier to match the MariaDB version with its appropriate Hibernate Dialect.

随着时间的推移,我们将根据 MariaDB 引入的新功能添加新方言。

...

如果您正在使用 MariaDB,最好从现在开始使用 MariaDB 特定的方言,因为将 MariaDB 版本与其适当的 Hibernate 方言相匹配要容易得多。

And https://hibernate.atlassian.net/browse/HHH-11457says:

https://hibernate.atlassian.net/browse/HHH-11457说:

since MySQL and MariaDB have gone in different directions, we might want to provide MariaDB Dialects as well.

For instance, it's not very intuitive for a Hibernate user to figure out that they need to use the MySQLInnoDb57Dialect to handle Timestamps with microsecond precision which have been available since MariaDB 5.3:

由于 MySQL 和 MariaDB 走向了不同的方向,我们可能也想提供 MariaDB 方言。

例如,对于 Hibernate 用户来说,确定他们需要使用 MySQLInnoDb57Dialect 来处理自 MariaDB 5.3 以来可用的微秒精度的时间戳不是很直观:

The Hibernate User Guide doesn't provide all usage information about how to use the dialects. Even the User Guide combines with the API docs may not be enough. Sometimes you'll have to look in the source codes for usage information. For example, MariaDB53Dialect.javacontains hidden non-JavaDoc comments that may be useful.

Hibernate 用户指南并未提供有关如何使用方言的所有使用信息。即使用户指南与 API 文档相结合也可能不够。有时您必须查看源代码以获取使用信息。例如,MariaDB53Dialect.java包含可能有用的隐藏的非 JavaDoc 注释。

Previously, to select a MySQL storage engine, such as MyISAM or InnoDB or default, you could switch between for example MySQL57InnoDBDialectand MySQL57Dialect. But they refactored the MySQL dialect hierarchy starting from Hibernate 5.2.8, as mentioned in a Hibernate blog post. Note that to select a storage engine, you should use a Environment Variable or System Property: hibernate.dialect.storage_engine. For example: hibernate.dialect.storage_engine = innodb.

以前,要选择 MySQL 存储引擎,例如 MyISAM 或 InnoDB 或默认值,您可以在 exampleMySQL57InnoDBDialectMySQL57Dialect. 但是他们从 Hibernate 5.2.8 开始重构了 MySQL 方言层次结构,如Hibernate 博客文章中所述。请注意,要选择存储引擎,您应该使用环境变量或系统属性:hibernate.dialect.storage_engine。例如:hibernate.dialect.storage_engine = innodb

XtraDB was the default MariaDB storage engine for MariaDB 10.1 and earlier, but since 10.2 it's InnoDB. So there may be cases that you want to explicitly mention the storage engine that Hibernate selects, so then you'll have to use the storage_enginevariable. Info about the storage_enginevariable (which isn't mentioned in the User Guide), can be found in the source of AvailableSettings.java.

XtraDB 是 MariaDB 10.1 及更早版本的默认 MariaDB 存储引擎,但自 10.2 以来它是 InnoDB。因此,在某些情况下,您可能希望明确提及 Hibernate 选择的存储引擎,因此您必须使用该storage_engine变量。关于storage_engine变量的信息(用户指南中没有提到),可以在AvailableSettings.java.

If you're using a MariaDB server older than 10.1.2 (which doesn't support fractional seconds), then you may want to provide the parameter useFractionalSeconds=falseto the JDBC URL, otherwise MariaDB Connector/J will not truncate timestamps internally, which can cause time comparison problem, which can cause Hibernate versioning problems and optimistic locking problems for temporal types.

如果您使用的 MariaDB 服务器早于 10.1.2(不支持小数秒),那么您可能需要将参数提供useFractionalSeconds=false给 JDBC URL,否则 MariaDB Connector/J 将不会在内部截断时间戳,这可能会导致时间比较问题,这会导致 Hibernate 版本控制问题和时间类型的乐观锁定问题。