Deprecated settings necessary for bootstrapping?


I’m new to Hibernate and first read the quickstart and introduction documents before I starting coding anything :wink: . So far, so good.

Now I’ve tried bootstrapping Hibernate via the following code:

var hibernateConfig = new org.hibernate.cfg.Configuration()
	.setProperty(AvailableSettings.URL, props.dbUrl)
	.setProperty(AvailableSettings.USER, props.dbUser)
	.setProperty(AvailableSettings.PASS, props.dbPassword)
	.setProperty(AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, Action.ACTION_UPDATE);

Set<Class<?>> entityClasses = getEntityClasses();

var sessionFactory = hibernateConfig.buildSessionFactory();

This works, the session factory is build and the database schema and tables are automatically created.

What puzzles me is that the first three setting parameters are marked as deprecated and that the JAKARTA_JDBC_* variants are now preferred. But when I use the latter ones, the code snippet above doesn’t work anymore; the session factory cannot be build and instead I see the following stack trace on my console:

2023-12-08 17:17:13,290 [XNIO-1 task-2] WARN  org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator(:203) - HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
2023-12-08 17:18:33,976 [XNIO-1 task-2] WARN  org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator(:345) - HHH000342: Could not obtain connection to query metadata
java.lang.UnsupportedOperationException: The application must supply JDBC connections
	at org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection( ~[hibernate-core-6.4.0.Final.jar:6.4.0.Final]
	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection( ~[hibernate-core-6.4.0.Final.jar:6.4.0.Final]
	at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.delegateWork( ~[hibernate-core-6.4.0.Final.jar:6.4.0.Final]

It took me some hours to find out that the reason for this is to be found in

		if ( connectionProvider == null ) {
			if ( configurationValues.get( AvailableSettings.URL ) != null ) {
				connectionProvider = new DriverManagerConnectionProviderImpl();

Shouldn’t the inner if statement not also check
configurationValues.get( AvailableSettings.JAKARTA_JDBC_URL ) != null when that’s preferred according to the Javadoc? Actually it’s ignored, and one has to use deprecated settings for bootstrapping…

Or is there a better way for doing this?

I think you might be hitting an issue that we are currently discussing here: HHH-17463 UnsupportedOperationException when using JAKARTA_JDBC_URL by dreab8 · Pull Request #7596 · hibernate/hibernate-orm · GitHub

Thanks for your fast answer. A short look at the PR seems to me to resolve the mentioned behavior, at least when it comes to ConnectionProviderInitiator#initiateService().