Why can't Spring Boot deduce Hibernate dialect?
15:35 21 Feb 2024

I can't start up my Spring Boot application

Caused by: org.hibernate.service.spi.ServiceException: 
Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due 
to: Unable to determine Dialect without JDBC metadata 
(please set 'jakarta.persistence.jdbc.url' for common cases or 'hibernate.dialect' when a 
custom Dialect implementation must be provided)

Here are my application properties (all of them):

spring:
  datasource:
    username: ${POSTGRES_USERNAME:postgres}
    password: ${POSTGRES_PASSWORD:postgres}
    url: ${POSTGRES_URL:jdbc:postgresql://localhost:5432/${POSTGRES_USERNAME}}

Here's my pom. I tried to trim to include only relevant parts (while ensuring it's still a valid pom you can copy and paste). Basically, to reproduce it, you only need to create a Boot project with a Data starter (maybe the driver too) so that Boot's autoconfiguration (the one with a DataSource) kicks in



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        3.2.2
         
    
    com.example
    token-service
    0.0.1-SNAPSHOT
    token-service
    token-service
    
        17
    
    
        
            org.springframework.boot
            spring-boot-starter-data-jpa
        
        
            org.postgresql
            postgresql
        
    

If I explicitly set the spring.jpa.database-platform property, it starts up fine. However, I never did it before when I used MySQL

spring:
# ...
  jpa:
    database-platform: org.hibernate.dialect.PostgreSQLDialect

Why can't Boot deduce the dialect?

java spring-boot hibernate spring-data-jpa