我正在学习如何配置 Hibernate 项目。我的配置文件如下:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- JDBC Database connection settings -->
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.username">username</property>
<property name="connection.password">password</property>
<!-- JDBC connection pool settings ... using built-in test pool -->
<property name="connection.pool_size">1</property>
<!-- Select our SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Echo the SQL to stdout -->
<property name="show_sql">true</property>
<!-- Set the current session context -->
<property name="current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>
虽然项目确实运行顺利并给出了预期的结果,但最后有一些日志引起了我的注意:
...
BUILD SUCCESSFUL in 1s
3 actionable tasks: 2 executed, 1 up-to-date
Oct 08, 2023 5:10:39 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate ORM core version 6.3.0.Final
Oct 08, 2023 5:10:39 PM org.hibernate.cache.internal.RegionFactoryInitiator initiateService
INFO: HHH000026: Second-level cache disabled
Oct 08, 2023 5:10:39 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using built-in connection pool (not intended for production use)
Oct 08, 2023 5:10:39 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: Loaded JDBC driver class: com.mysql.cj.jdbc.Driver
Oct 08, 2023 5:10:39 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001012: Connecting with JDBC URL [jdbc:mysql://localhost:3306/test]
Oct 08, 2023 5:10:39 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {password=****, user=joun}
Oct 08, 2023 5:10:39 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Oct 08, 2023 5:10:39 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH10001115: Connection pool size: 1 (min=1)
Oct 08, 2023 5:10:39 PM org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator getJdbcEnvironmentUsingJdbcMetadata
WARN: HHH000339: Could not obtain connection metadata: java.sql.SQLSyntaxErrorException: Unknown column 'RESERVED' in 'where clause'
Oct 08, 2023 5:10:39 PM org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl constructDialect
WARN: HHH90000025: MySQLDialect does not need to be specified explicitly using 'hibernate.dialect' (remove the property setting and it will be selected by default)
Oct 08, 2023 5:10:40 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PoolState stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:mysql://localhost:3306/test]
5:10:40 PM: Execution finished ':Main.main()'.
在我看来,最后两个警告与
connection metadata
和 dialect
有关。虽然我不知道如何处理第一个问题,但我认为第二个问题与这些行有关
<!-- Select our SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
我尝试过将方言更改为其他名称,例如
org.hibernate.dialect.MariaDBDialect
或删除它们,但最终没有结果。
我可以得到一些关于如何修复这两个警告的建议吗?
按照 Mark Rotteveel 的建议,我尝试更改依赖项以使用 MariaDB 而不是 MySQL 本身。
dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
// hibernate
implementation("org.hibernate.orm:hibernate-core:6.3.0.Final")
// mysql / mariadb
// implementation("mysql:mysql-connector-java:8.0.27")
implementation("org.mariadb.jdbc:mariadb-java-client:3.1.4")
}
结果我也不必指定驱动程序和方言。
<!-- JDBC Database connection settings -->
<!-- <property name="connection.driver_class">org.mariadb.jdbc.Driver</property> -->
<property name="connection.url">jdbc:mariadb://localhost:3306/test</property>
<property name="connection.username">joun</property>
<property name="connection.password">123</property>
<!-- JDBC connection pool settings ... using built-in test pool -->
<property name="connection.pool_size">1</property>
<!-- Select our SQL dialect -->
<!-- <property name="dialect">org.hibernate.dialect.MariaDBDialect</property> -->
<!-- Echo the SQL to stdout -->
<property name="show_sql">true</property>