Hibernate6 with HikariCP on Springboot fails to boot

When trying to use Hibernate and HikariCP on a Springboot Application, it fails to parse the JNDI name on any Hibernate call.

Here is the project where I am facing this Issue here
The entire code for the SQL handling is within a library

I have been trying to fix this Issue for the past month or so, sadly I was not able to.
It seems like it has something to do with an internal change within hibernate or springboot, since reverting to an older version of Hibernate it worked for a while, but when upgrading Springboot it did not work anymore.

Exception:

org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: Error parsing JNDI name [com.zaxxer.hikari.HikariDataSource]
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:276) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:238) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:215) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.boot.model.relational.Database.<init>(Database.java:45) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.getDatabase(InFlightMetadataCollectorImpl.java:223) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:191) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:169) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:128) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:451) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:102) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:910) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at de.presti.ree6.sql.SQLSession.buildSessionFactory(SQLSession.java:231) ~[Ree6-SQL-2.1.5.jar:2.1.5]
	at de.presti.ree6.sql.SQLSession.getSessionFactory(SQLSession.java:314) ~[Ree6-SQL-2.1.5.jar:2.1.5]
	at de.presti.ree6.sql.SQLWorker.getEntityList(SQLWorker.java:2342) ~[Ree6-SQL-2.1.5.jar:2.1.5]
	at de.presti.ree6.sql.SQLWorker.getEntityList(SQLWorker.java:2311) ~[Ree6-SQL-2.1.5.jar:2.1.5]
	at de.presti.ree6.backend.utils.data.DatabaseStorageBackend.loadCredentials(DatabaseStorageBackend.java:23) ~[classes/:na]
	at com.github.philippheuer.credentialmanager.CredentialManager.load(CredentialManager.java:188) ~[credentialmanager-0.2.2.jar:na]
	at com.github.philippheuer.credentialmanager.CredentialManager.<init>(CredentialManager.java:64) ~[credentialmanager-0.2.2.jar:na]
	at com.github.philippheuer.credentialmanager.CredentialManagerBuilder.build(CredentialManagerBuilder.java:48) ~[credentialmanager-0.2.2.jar:na]
	at de.presti.ree6.backend.Server.load(Server.java:178) ~[classes/:na]
	at de.presti.ree6.backend.WebinterfaceApplication.main(WebinterfaceApplication.java:31) ~[classes/:na]
Caused by: org.hibernate.engine.jndi.JndiException: Error parsing JNDI name [com.zaxxer.hikari.HikariDataSource]
	at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:134) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:95) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:98) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:135) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:247) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:215) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:391) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.getJdbcEnvironmentUsingJdbcMetadata(JdbcEnvironmentInitiator.java:259) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:105) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:129) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	... 20 common frames omitted
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or in an application resource file: java.naming.factory.initial
	at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:704) ~[na:na]
	at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305) ~[na:na]
	at java.naming/javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:342) ~[na:na]
	at java.naming/javax.naming.InitialContext.getNameParser(InitialContext.java:497) ~[na:na]
	at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:128) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]
	... 31 common frames omitted

Unless you can reproduce this error with just Hibernate ORM, ideally by using our test case template (https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java), then we will have to assume this is a problem with Spring.

I will check if I can replicate it with the test case template, but I have noticed that this is not a Issue by Springboot, since starting today this also happends to my normal Java Application?

After even more testing and using the test case template, I have noticed that Hibernate will use the Datasource Class if a Driver Class is missing and that caused this Issue. Is that a wanted behaviour?

I don’t know what configuration you are using, but if you’re expecting a DriverManagerConnectionProvider but fail to configure the driver class, then you will obviously get something different. Depending on what you configured you might get a different connection provider or an error.

Well you can ignore whatever I said, it sadly still fails. Even if I set the correct driver class, I receive the same error. So before trying to find out the solution on my end, I would rather ask for how exactly I should test this with the test case template, so I can first check if there is something wrong on my end.

After alot more testing I figured out this is indeed something related to Hibernate, or a misconfiguration that happends to cause the Issue on any Hibernate version after 6.2.9?

When trying to replicated this Issue on 6.2.9, it does happend and the application starts without any Issue?

I don’t know what you’re trying to say with your last sentence. If you think this is a bug, please provide a reproducer based on our test case template.

I apologize, I have typo in the last sentence.

What I mean was when using the version 6.2.9 or any older one, this error does not occure and everything works as expected. But using any version above such as 6.2.10, the error occures.

For the test case template, as already asked in a previous comment.
How should I excactly try using it? Should I just clone it and use my hikari configuration and thats it or?

Yeah, clone it and apply the configuration/entities so that when running the test, the error you are seeing is reproduced.

Yep the test failed.

It failed with the standalone test, and the only modifications I did where adding Hikari, Hibernate-Hikari into the pom.xml and adding these configuration values:

                .applySetting("hibernate.connection.datasource", "com.zaxxer.hikari.HikariDataSource")
				.applySetting("hibernate.connection.provider_class", "org.hibernate.hikaricp.internal.HikariCPConnectionProvider")
				.applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
				.applySetting("hibernate.connection.driver_class", "org.h2.Driver");

Well, this is a misconfiguration. hibernate.connection.datasource is supposed to be a JNDI name that’s why it tries to access/parse that as JNDI name. You’re missing url, username and password configurations. See Hibernate ORM User Guide