Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException from Hibernate ORM when there is a problem establishing a connection #44645

Closed
shawkins opened this issue Nov 22, 2024 · 8 comments · Fixed by #46041
Closed
Assignees
Labels
area/hibernate-orm Hibernate ORM good first issue Good for newcomers kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus.
Milestone

Comments

@shawkins
Copy link
Contributor

Describe the bug

In some circumstances hibernate fails to report a meaningful error message and instead shows a nullpointerexception:

2024-11-21 19:00:18,827 WARN  [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (JPA Startup Thread) HHH000342: Could not obtain connecti                    on to query metadata: java.lang.NullPointerException: Cannot throw exception because the return value of "java.util.function.BiFunction.apply(Object, Obj                    ect)" is null
        at org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate.doTheWork(JtaIsolationDelegate.java:202)
        at org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate.lambda$delegateWork$3(JtaIsolationDelegate.java:91)
        at org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate.doInSuspendedTransaction(JtaIsolationDelegate.java:123)
        at org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate.delegateWork(JtaIsolationDelegate.java:88)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.getJdbcEnvironmentUsingJdbcMetadata(JdbcEnvironmentInitiator.java:276)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:107)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68)
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:130)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:238)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:215)
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:52)
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:136)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:247)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:215)
        at org.hibernate.boot.internal.SessionFactoryOptionsBuilder.<init>(SessionFactoryOptionsBuilder.java:276)
        at io.quarkus.hibernate.orm.runtime.recording.PrevalidatedQuarkusMetadata.buildSessionFactoryOptionsBuilder(PrevalidatedQuarkusMetadata.java:70)
        at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:84)
        at io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider.createEntityManagerFactory(FastBootHibernatePersistenceProvider.java:72)
        at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)
        at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
        at io.quarkus.hibernate.orm.runtime.JPAConfig$LazyPersistenceUnit.get(JPAConfig.java:157)
        at io.quarkus.hibernate.orm.runtime.JPAConfig$1.run(JPAConfig.java:64)
        at java.base/java.lang.Thread.run(Thread.java:1583)

See keycloak/keycloak#35181 - this error also appears in other Keycloak and Quarkus issues, such as #31842

Expected behavior

A meaningful exception.

Actual behavior

A nullpointerexception.

How to Reproduce?

Keycloak is using a persistence.xml, I'm not sure if that's a requirement to reproduce this. If you then misconfigure the datasource, such as an invalid password, you should see the null pointer exception.

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

3.8.5

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@shawkins shawkins added the kind/bug Something isn't working label Nov 22, 2024
@quarkus-bot quarkus-bot bot added the area/hibernate-orm Hibernate ORM label Nov 22, 2024
Copy link

quarkus-bot bot commented Nov 22, 2024

/cc @gsmet (hibernate-orm), @yrodiere (hibernate-orm)

@yrodiere
Copy link
Member

I think the most likely cause would be either the sqlExceptionConverter being passed a null exception (in which case the bug is in whatever called the sqlExceptionConverter), or the sqlExceptionConverter returning null as the "converted" exception (in which case the bug is in the sqlExceptionConverter)

Quoting keycloak/keycloak#35014 (comment) :

it seems caused by the exception converter returning null, which certainly looks like a bug, possibly caused by this line.

We probably need, at least, to check in Hibernate ORM that sqlExceptionConverter implementations never return null, because I think that would be a bug.

@yrodiere
Copy link
Member

Also, thanks for creating the bug report @shawkins :)

@yrodiere yrodiere changed the title NullPointerException from hibernated when there is a problem establishing a connection NullPointerException from Hibernate ORM when there is a problem establishing a connection Nov 22, 2024
@gsmet gsmet added triage/upstream kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus. and removed triage/upstream kind/bug Something isn't working labels Nov 25, 2024
@yrodiere yrodiere added the good first issue Good for newcomers label Dec 4, 2024
@dreab8
Copy link
Contributor

dreab8 commented Dec 18, 2024

I think this issue may be related to https://hibernate.atlassian.net/browse/HHH-17872 that should have been fixed in Hibernate 6.4.5

@dreab8
Copy link
Contributor

dreab8 commented Dec 18, 2024

discussing with @marko-bekhta we probably found the cause of the issue.

@dreab8 dreab8 self-assigned this Dec 18, 2024
@dreab8
Copy link
Contributor

dreab8 commented Dec 18, 2024

@elmodeer
Copy link

elmodeer commented Jan 8, 2025

can I work on this @yrodiere ? or is it already fixed ?

@yrodiere
Copy link
Member

yrodiere commented Jan 8, 2025

@elmodeer Thanks for your proposal, but the problem is in Hibernate ORM as indicated in the previous comment, and it's already being worked on: hibernate/hibernate-orm#9464

@quarkus-bot quarkus-bot bot added this to the 3.19 - main milestone Feb 3, 2025
@gsmet gsmet modified the milestones: 3.19 - main, 3.18.2 Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM good first issue Good for newcomers kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants