Docker: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set

I came across this problem when dockerizing a Springboot application. A number of people have also come across this issue and the answers given weren’t all that helpful.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
[...]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
[...]
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)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)

The issue is that a SpringBoot application that interfaces to an external MySQL Database does not connect. The stacktrace given is a bit of a red herring, it has nothing to do with the dialect settings (adding those did not solive the problem).

The problem stems from the networking stack from within Docker. Inside a docker container, loopback addresses such as 127.0.0.1 or localhostĀ  will refer to the localhost inside of the container only! It will not refer to any services that are running on the docker host – that would (in a non docker world) be ordinarily referenced by localhost.

A quick fix is to change the application.properties file to use a qualified IP address and not a loopback address.

For instance change 127.0.0.1 to the output of the command in ipconfig or ifconfig

The result should hopefully look like this

03:18:30.416 [main] INFO o.a.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-8080"]
03:18:30.426 [main] INFO o.a.tomcat.util.net.NioSelectorPool - Using a shared selector for servlet write/read
03:18:30.469 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path ''

Leave a Reply

Your email address will not be published. Required fields are marked *