In this short post, I’d like to share solution to fix a common error that every programmer will very likely encounter: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set.

You may get the exception like this:

Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

       at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
 

Why does this error occur?

This error means Hibernate framework tried to determine a suitable database dialect class  from application’s configuration but it couldn’t find any. The database dialect class helps Hibernate generates SQL statements optimized for a particular relational database.

But the real cause maybe that it could not find the database schema name specified in the JDBC URL (Unknown database 'dbname').

This is runtime error that causes the application failed to start and terminated immediately.

 

How to fix?

The solution to fix this error is very simple: you need to update the configuration class (application.properties, hibernate.cfg.xml or persistence.xml) file to specify the appropriate database dialect class, OR correct the schema name in JDBC URL to match one in database, OR create a new database schema whose name matches the one specified in JDBC URL.

For example, if you use Spring Boot, then update the application.properties file as follow:

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect


If you use newer version of Spring Boot that comes with newer version of Hibernate ORM, then the driver class name for MySQL is MySQLDialect:

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
If your application uses hibernate.cfg.xml or persistence.xmlfile, put the following property:

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  

For your references, below are the database dialect class names to work with other database systems:

  • Oracle: Oracle10gDialect, Oracle12cDialect, Oracle8iDialect, Oracle9iDialect, OracleDialect
  • PostgreSQL: PostgreSQL81Dialect, PostgreSQL82Dialect, PostgreSQL91Dialect,… PostgreSQLDialect
  • H2: H2Dialect
  • MariaDB: MariaDBDialect, MariaDB102Dialect, MariaDB103Dialect, MariaDB53Dialect…
  • DB2: DB2Dialect, DB2iDialect, DB2zDialect, DB2390Dialect, DB2400Dialect, …
  • SQL Server: SQLServerDialect, SQLServer2016Dialect, SQLServer2012Dialect, SQLServer2008Dialect…
  • Derby: DerbyDialect, DerbyTenFiveDialect, DerbyTenSixDialect, DerbyTenSevenDialect
 

NOTES:

If you use Spring framework with Spring Boot, another solution is upgrading to Spring Boot 3.x that comes with Hibernate framework version that does not require explicit dialect information - no need to specify the hibernate.dialect property - as it can auto-detect the appropriate dialect class. However, you will need to change more code to be compatible with new version of Spring and Hibernate frameworks.

I hope you found this article as a helpful guide to fix the error Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set - when developing Java applications using Hibernate framework. You can also watch the following video to see how to fix this error in action:

 

Recommended Hibernate Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.



Add comment