HibernateEntityManagerFactoryIntegrator evaluates wrong DBMS name when using Hibernate with MariaDB103Dialect and H2
See original GitHub issueDescription
DBMS name determination fails for H2 in MariaDB-Mode. Logged output is
WARNING [com.bla.per.spi.EntityManagerFactoryIntegrator] (main) Could not register the function 'json_get' because there is neither an implementation for the dbms 'mysql' nor a default implementation!
Expected behavior
DBMS name is evaluated as mysql8
Actual behavior
DBMS name is evaluated as mysql
-> database functions newer than mysql5/mariadb5 are not usable
Steps to reproduce
- use jdbc connection:
url: jdbc:h2:mem:maindb;MODE=MySQL;DATABASE_TO_LOWER=TRUE;;init=SET collation german;DB_CLOSE_DELAY=-1
- use hibernate dialect:
org.hibernate.dialect.MariaDB103Dialect
- use
com.blazebit.persistence.CriteriaBuilderFactory
Logged output is
WARNING [com.bla.per.spi.EntityManagerFactoryIntegrator] (main) Could not register the function 'json_get' because there is neither an implementation for the dbms 'mysql' nor a default implementation!
Suspected defect
Explanation:
org.hibernate.dialect.MariaDB103Dialect
is aMySQLDialect
- H2 runs in MySQL/MariaDB - compatibility mode (see http://h2database.com/html/features.html#compatibility)
- calling
connection.getMetaData().getDatabaseMajorVersion()
returns 1 here, this seems to be the version of H2
I think it is wrong to create a connection here, as all needed information is already present in the form of the configured hibernate dialect.
Proposed solution:
if (dialect instanceof org.hibernate.dialect.MySQL8Dialect) {
return "mysql8";
} else if (dialect instanceof org.hibernate.dialect.MariaDB10Dialect) {
return "mysql8";
} else if (dialect instanceof MySQLDialect) {
return "mysql";
} else if (dialect instanceof DB2Dialect) {
return "db2";
} else if (dialect instanceof PostgreSQL81Dialect) {
return "postgresql";
} else [...]
Environment
Version: 1.5.1 JPA-Provider: Hibernate 5.4.28 DBMS: H2 in SQL Mode (which is to be used for MySQL and MariaDB) Application Server: Quarkus
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Blazebit - Bountysource
There are use cases where entity views contain a list of strings as a comma ... HibernateEntityManagerFactoryIntegrator evaluates wrong DBMS name when using...
Read more >Hibernate uses wrong column name despite all anotations
Table of my database is created using following sql : CREATE TABLE students ( "ID" UUID, "First_Name" VARCHAR(50), "Last_Name" ...
Read more >Common Hibernate Exceptions - Baeldung
Many conditions can cause exceptions to be thrown while using Hibernate. These can be mapping errors, infrastructure problems, SQL errors, ...
Read more >JDBC Connection and Dialect Configuration in Hibernate
You can use the following configuration parameters to configure the JDBC connection in Hibernate: javax.persistence.jdbc.driver – The fully qualified class name ...
Read more >Hibernate ORM 5.2.18.Final User Guide - Red Hat on GitHub
Using Hibernate's built-in (and unsupported) pooling; 7.7. ... in mapping the Contact table, all attributes except for name would be basic types.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @mickroll,
thanks for the report. I’ll try to adapt the code to try to rely more on the dialect, but since the MySQL8 Dialect was only added in a very late Hibernate version, the connection acquisition is sometimes necessary. It would be a bummer not to support detecting MySQL8 for older Hibernate versions or when people use a custom dialect.
Apart from that, you won’t be able to use the
json_get
function with H2 as it, as far as I know, does not support the underlying json access functions even in MySQL compatible mode. So if you want to use the json functions, you will have to use MySQL or MariaDB.From what i can see by debugging our application, hibernate on H2 does not close the logical connection, because the underlying physical connection is not present. Have to check as soon as we have a real MariaDB to connect to.
Nevermind, that’s completely out of scope of this issue.