为什么 hibernate 严格要求定义 hibernate.dialect 属性 而 JPA 规范没有强制要求?

Why does hibernate strictly asks to define the hibernate.dialect property while the JPA specification doesn't makes it mandatory?

在使用 hibernate 学习 java 持久性时,我发现 hibernate 强制定义方言 属性。我很困惑 SQL 是通用语言,它用于数据库通信,为什么我们要为不同的数据库选择不同的方言?为什么 hibernate 严格要求定义方言而 JPA 规范不关心它?

通常Hibernate 不需要设置hibernate.dialect 属性。

看看文档在第 7.12 章中所说的内容:http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#database-dialect

7.12. Database Dialect

Although SQL is relatively standardized, each database vendor uses a subset and superset of ANSI SQL defined syntax. This is referred to as the database’s dialect. Hibernate handles variations across these dialects through its org.hibernate.dialect.Dialect class and the various subclasses for each database vendor.

In most cases Hibernate will be able to determine the proper Dialect to use by asking some questions of the JDBC Connection during bootstrap. For information on Hibernate’s ability to determine the proper Dialect to use (and your ability to influence that resolution), see Dialect resolution.

If for some reason it is not able to determine the proper one or you want to use a custom Dialect, you will need to set the hibernate.dialect setting.