If there is no Dialect set (which Hibernate 6.4 recommends), all you get is a bunch of stack traces, if JDBC URL is misspelled, db server down, etc. the simple cause is hidden from a sysadmin:
sf = new Configuration()…buildSessionFactory();
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
If Dialect is set, you get a clue after you try the first query:
Jun 20, 2024 3:55:19 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 3D000
Jun 20, 2024 3:55:19 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: FATAL: database “tsX” does not exist
Now the cause is so obvious, I won’t waste hours looking thru source code…
Should there not be a default SqlExceptionHelper set during the Metadata query phase of creating a SessionFactory? Can I set one, and have it upgraded later when a more specific one is known?
Hi, this sounds very similar to [HHH-17872] - Hibernate JIRA, which was solved in 6.5. Could you please try updating the HIbernate version and let us know if the issue persists?
I am using Hibernate 6.5.2.Final, sorry for the confusion I was referring to 6.4 in the context of the online documentation I was reading.
Then we might want to look into improving this. Could you please create a new ticket in our issue tracker regarding this improvement request? Ideally, attaching a reproducer test case based on our our test case template that demonstrates the behavior would be great.
On creating a minimal reproducer, I found that agroal-pool 2.2 with hibernate-agroal is the trigger. Hibernate 6.5.2.Final and 7.0.0.Alpha3. Postgres JDBC driver.
Not sure what the next step is.
Jun 26, 2024 6:03:17 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate ORM core version 7.0.0.Alpha3
Jun 26, 2024 6:03:18 PM org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator getJdbcEnvironmentUsingJdbcMetadata
WARN: HHH000342: Could not obtain connection to query metadata
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
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.delegateWork(JdbcIsolationDelegate.java:116)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.getJdbcEnvironmentUsingJdbcMetadata(JdbcEnvironmentInitiator.java:292)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:125)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:78)
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.boot.model.relational.Database.<init>(Database.java:45)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.getDatabase(InFlightMetadataCollectorImpl.java:282)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:215)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:221)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:197)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:152)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:438)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:97)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:946)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:996)
at com.mycompany.ormtestexception.OrmTestException.main(OrmTestException.java:28)
sf = new Configuration()
.setProperty(AvailableSettings.JAKARTA_JDBC_URL, "jdbc:postgresql://localhost/DOESNOTEXIST")
.setProperty(AvailableSettings.JAKARTA_JDBC_USER, "me")
.setProperty(AvailableSettings.JAKARTA_JDBC_PASSWORD, "uhh")
.setProperty("hibernate.agroal.maxSize", "10")
// use to get exception on first query
//.setProperty(AvailableSettings.DIALECT, "org.hibernate.dialect.PostgreSQLDialect")
.buildSessionFactory();
As I said on my previous comment, a new ticket in our issue tracker is the way to report bugs / improvement requests.