spring-projects / spring-projects/spring-framework

NullPointerException in Hibernate when connecting to PostgreSQL: sqlExceptionHelper() returns null

Open
#36,525 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

Description:
When starting a Spring Boot application with Hibernate and PostgreSQL, I get the following error:

java.lang.NullPointerException: Cannot invoke "org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(java.sql.SQLException, String)"
because the return value of "org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.sqlExceptionHelper()" is null

Steps to Reproduce:

Use Spring Boot 3.x with Hibernate 6.x
Configure PostgreSQL as follows:

application.properties:

spring.datasource.url=jdbc:postgresql://localhost:5432/testdb spring.datasource.username=testuser spring.datasource.password=testpass spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect spring.jpa.hibernate.ddl-auto=update

docker-compose.yml:

version: '3.9' services: postgres: image: postgres:16 environment: POSTGRES_USER: testuser POSTGRES_PASSWORD: testpass PGDATA: /data/postgres ports: - "5432:5432"

Start PostgreSQL container and run the Spring Boot app.

Expected Behavior:
Hibernate should connect to PostgreSQL and initialize the schema.

Actual Behavior:
Application fails immediately with a NullPointerException in Hibernate related to sqlExceptionHelper().

Environment:

macOS Ventura
Java 17
Spring Boot 3.3.2
Hibernate 6.x
PostgreSQL 16
Docker 24.x

Notes:

Verified that the database credentials and URL are correct.
Running PostgreSQL locally outside Docker works fine.
Error appears when using Dockerized PostgreSQL with Spring Boot running locally or in another container.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the configuration in application.properties with the PostgreSQL service from docker-compose.yml, using the stated Spring Boot, Hibernate, and PostgreSQL versions. Compare the Dockerized setup with the locally working PostgreSQL setup and trace the startup failure around sqlExceptionHelper(). Done means the cause is isolated and schema initialization completes without the NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, java, postgresql, spring-boot
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.