Search code examples
javamysqlhibernatejdbc

Hibernate error in missing dialect while suggested not to include so


I am learning how to configure a Hibernate project. My config file is as follows:

<!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>

While the project did run smoothly and give out desired results, there were some logs at the end that caught my attentions:

...
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()'.

Seems to me that the last two warnings relate to the connection metadata and dialect. While I am no idea how to deal with the first one, I am thinking the second one relate to these lines

<!-- Select our SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

I have tried changing the dialect to other name such as org.hibernate.dialect.MariaDBDialect or remove them, but eventually yields no results.

May I get some suggestions on how to fix these two warnings?


Solution

  • As suggested by Mark Rotteveel, I tried to change my dependencies to use MariaDB rather than MySQL itself.

    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")
    }
    

    Turns out I don't have to specify the driver and the dialect either.

        <!-- 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>