0

I have a Spring project with a PostgreSQL database. I'm trying to add a custom dialect, but I've noticed that Spring is not loading it.

My dialect:

package org.company.configuration;

public class CustomPostgreSQLDialect extends PostgreSQLDialect {

    private static final Logger LOGGER = LoggerFactory.getLogger(CustomPostgreSQLDialect.class);

    public CustomPostgreSQLDialect() {
        super();
        LOGGER.warn("=== CustomPostgreSQLDialect INITIALIZED ===");
    }
}

and this is how I use it in the properties file:

spring:
  jpa:
    database: POSTGRESQL
    database-platform: org.company.configuration.CustomPostgreSQLDialect

at startup I don't see the log === CustomPostgreSQLDialect INITIALIZED ===, any idea what might be the issue? I've tried also to call it like this:

spring:
  jpa:
    properties:
      hibernate:
        dialect: org.company.configuration.CustomPostgreSQLDialect

This didn't work either. I tried recompiling and force cache cleaning via the command mvn clean compile -U, but still no luck!

1
  • Use either spring.jpa.database or spring.jpa.database-platform not both. As you want a custom one ditch the spring.jpa.database as that will only resolve to the default Postgres Dialect. Commented Oct 8 at 8:42

1 Answer 1

0

Spring Boot 3.5.6

Before testing your custom CustomPostgreSQLDialect, use the defaults without specifying a dialect. Add the debug logging setting org.hibernate.orm.dialect: DEBUG to your application.yaml file and test. You should normally see the default Using dialect:org.hibernate.dialect.PostgreSQLDialect, version: 18.0 logged.

This step is to confirm that your JPA application runs correctly. After confirming that your JPA application runs correctly, configure it to use the CustomPostgreSQLDialect ( dialect: org.company.configuration.CustomPostgreSQLDialect).

application.yml - default - no dialect config

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/demodb
    driver-class-name: org.postgresql.Driver
    username: demouser
    password: Passw0rd!

  jpa:
    properties:
      hibernate:
        format_sql: true
    hibernate:
      ddl-auto: update
    show-sql: true

logging:
  level:
    # --- Spring Data / ORM ---
    org.springframework.data.jpa: DEBUG

    # --- Hibernate ---    
    org.hibernate.orm.dialect: DEBUG
    org.hibernate.engine.jdbc.env.internal: DEBUG
    org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl: DEBUG
    
    # --- Custom Dialect ---
    com.example.CustomPostgreSQLDialect: DEBUG

Build

mvn clean package

Run

java -jar target/app.jar

Output

 :: Spring Boot ::                (v3.5.6)

2025-10-09T20:22:40.623+08:00 DEBUG 14973 --- [           main] o.h.e.j.e.i.JdbcEnvironmentInitiator     : Database ->
       name : PostgreSQL
    version : 18.0 (Debian 18.0-1.pgdg13+3)
      major : 18
      minor : 0
2025-10-09T20:22:40.623+08:00 DEBUG 14973 --- [           main] o.h.e.j.e.i.JdbcEnvironmentInitiator     : Driver ->
       name : PostgreSQL JDBC Driver
    version : 42.7.7
      major : 42
      minor : 7

2025-10-09T20:22:40.689+08:00 DEBUG 14973 --- [           main] org.hibernate.orm.dialect                : HHH035001: Using dialect: org.hibernate.dialect.PostgreSQLDialect, version: 18.0
  • You can find out that the PostgreSQL version is 18. (My PostgreSQL server version)
  • If dialect is not set, the default is org.hibernate.dialect.PostgreSQLDialect, version: 18.0

Find out JPA, Hibernate version

mvn dependency:tree

get

  • org.springframework.boot:spring-boot-starter-data-jpa:jar:3.5.6:compile
  • org.springframework.data:spring-data-jpa:jar:3.5.4:compile
  • org.hibernate.orm:hibernate-core:jar:6.6.29.Final:compile
  • org.hibernate.common:hibernate-commons-annotations:jar:7.0.3.Final:runtime

So, Hibernate 6.6.

https://docs.jboss.org/hibernate/orm/6.6/javadocs/org/hibernate/dialect/package-summary.html

  • PostgreSQLDialect A SQL dialect for PostgreSQL 11 and above.

CustomPostgreSQLDialect.java

package org.company.configuration;

import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CustomPostgreSQLDialect extends PostgreSQLDialect {
    private static final Logger logger = LoggerFactory.getLogger(CustomPostgreSQLDialect.class);

    public CustomPostgreSQLDialect() {
        super();
        logger.warn(">>> CustomPostgreSQLDialect INITIALIZED");
    }

    public CustomPostgreSQLDialect(DialectResolutionInfo info) {
        super(info);
        logger.warn(">>> CustomPostgreSQLDialect INITIALIZED DialectResolutionInfo info");
    }
}

application.yml - CustomPostgreSQLDialect

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/demodb
    driver-class-name: org.postgresql.Driver
    username: demouser
    password: Passw0rd!

  jpa:
    properties:
      hibernate:
        dialect: org.company.configuration.CustomPostgreSQLDialect
        format_sql: true
    hibernate:
      ddl-auto: update
    show-sql: true

logging:
  level:
    # --- Spring Data / ORM ---
    org.springframework.data.jpa: DEBUG

    # --- Hibernate ---
    org.hibernate.orm.dialect: DEBUG
    org.hibernate.engine.jdbc.env.internal: DEBUG
    org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl: DEBUG
    
    # --- Custom Dialect ---
    com.example.CustomPostgreSQLDialect: DEBUG

Build

mvn clean package

Run

java -jar target/app.jar

Output

 :: Spring Boot ::                (v3.5.6)

2025-10-09T20:27:23.436+08:00 DEBUG 15456 --- [           main] o.h.e.j.e.i.JdbcEnvironmentInitiator     : Database ->
       name : PostgreSQL
    version : 18.0 (Debian 18.0-1.pgdg13+3)
      major : 18
      minor : 0
2025-10-09T20:27:23.436+08:00 DEBUG 15456 --- [           main] o.h.e.j.e.i.JdbcEnvironmentInitiator     : Driver ->
       name : PostgreSQL JDBC Driver
    version : 42.7.7
      major : 42
      minor : 7

2025-10-09T20:27:23.463+08:00  WARN 15456 --- [           main] o.c.c.CustomPostgreSQLDialect            : >>> CustomPostgreSQLDialect INITIALIZED DialectResolutionInfo info
2025-10-09T20:27:23.464+08:00 DEBUG 15456 --- [           main] org.hibernate.orm.dialect                : HHH035001: Using dialect: org.company.configuration.CustomPostgreSQLDialect, version: 18.0
  • DEBUG 15456 --- [ main] org.hibernate.orm.dialect : HHH035001: Using dialect: org.company.configuration.CustomPostgreSQLDialect, version: 18.0
  • WARN 15456 --- [ main] o.c.c.CustomPostgreSQLDialect : >>> CustomPostgreSQLDialect INITIALIZED DialectResolutionInfo info

Please add a logging level setting to application.yml to display which class of dialect is being loaded.

Please note that the log shows that the CustomPostgreSQLDialect(DialectResolutionInfo info) constructor with the passed parameters is called instead of the empty constructor.

Also, remember to add the org.hibernate.orm.dialect: DEBUG logging setting to your application.yaml file. You should see HHH035001: Using dialect: org.company.configuration.CustomPostgreSQLDialect, version: 18.0 in the log, confirming that CustomPostgreSQLDialect is being used.

This version of the answer is modified from the answer to a previous question (CustomH2Dialect in Hibernate 6.5). CustomH2Dialect in Hibernate 6.5 (CustomH2Dialect in Hibernate 6.5)

Sign up to request clarification or add additional context in comments.

4 Comments

spring does not load my dialet, even after setting in the yaml file I see this in the logs HHH035001: Using dialect: org.hibernate.dialect.PostgreSQLDialect, version: 15.12
Maybe you should post the contents of your complete minimal working Spring project so others can reproduce the same results.
After change yaml file, remember to re-run the build (mvn clean package), and then re-run the program (java -jar target/app.jar)
Regarding your question, the tag is Spring instead of Spring Boot, but your configuration file uses application.yaml . So, I need to confirm whether your application is Spring Boot or Spring.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.