Hibernate of current version doesn't match h2
I use hibernate and h2 inherited from the parent pom.xml whose version are 5.2.18.Final.
But I find the org.hibernate.dialect.H2Dialect extends from org.hibernate.dialect.Dialect didn't override method getCurrentSchemaCommand, which leeds it reture null.
Then I received an exception when I use hibernate to connect h2database:
org.hibernate.HibernateException: Use of DefaultSchemaNameResolver requires Dialect to provide the proper SQL statement/command but provided Dialect [org.hibernate.dialect.H2Dialect] did not return anything from Dialect#getCurrentSchemaCommand
at org.hibernate.engine.jdbc.env.internal.DefaultSchemaNameResolver$SchemaNameResolverFallbackDelegate.resolveSchemaName(DefaultSchemaNameResolver.java:100)
at org.hibernate.engine.jdbc.env.internal.DefaultSchemaNameResolver.resolveSchemaName(DefaultSchemaNameResolver.java:76)
......
It occurs becaus
public String resolveSchemaName(Connection connection, Dialect dialect) throws SQLException {
final String command = dialect.getCurrentSchemaCommand();
if ( command == null ) {
throw new HibernateException(
"Use of DefaultSchemaNameResolver requires Dialect to provide the " +
"proper SQL statement/command but provided Dialect [" +
dialect.getClass().getName() + "] did not return anything " +
"from Dialect#getCurrentSchemaCommand"
);
}
......
}
but the code can run successfully for some reasons. you can reproduce this case in my code Is is necessary to fix it? Maybe a new version of hibernate?
Hi, I'd like to work on this issue. Could it be assigned to me if still available?
Thanks @Linly1080, please go ahead
@iluwatar sorry, I have no time to do the work now.
The issue is still present in 5.4.24. To verify, run com.iluwatar.metamapping.AppTest and look for
org.hibernate.HibernateException: Use of DefaultSchemaNameResolver requires Dialect to provide the proper SQL statement/command but provided Dialect [org.hibernate.dialect.H2Dialect] did not return anything from Dialect#getCurrentSchemaCommand
at org.hibernate.engine.jdbc.env.internal.DefaultSchemaNameResolver$SchemaNameResolverFallbackDelegate.resolveSchemaName(DefaultSchemaNameResolver.java:100)
at org.hibernate.engine.jdbc.env.internal.DefaultSchemaNameResolver.resolveSchemaName(DefaultSchemaNameResolver.java:76)
We would get rid of the HibernateException by implementing a custom SchemaNameResolver
By default, Hibernate uses the [org.hibernate.dialect.Dialect#getSchemaNameResolver](https://docs.jboss.org/hibernate/orm/5.4/javadocs/org/hibernate/dialect/Dialect.html#getSchemaNameResolver--). You can customize how the schema name is resolved by providing a custom implementation of the [SchemaNameResolver](https://docs.jboss.org/hibernate/orm/5.4/javadocs/org/hibernate/engine/jdbc/env/spi/SchemaNameResolver.html) interface.
https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#_table_qualifying_options
I advise closing this issue because it is only a strange error message from some weird internal Hibernate implementation. You will see a similar exception for all MySQLDialects because MySQL doesn't support schemas.