Skip to content

Hibernate default blocking PU + named reactive PU causes errors #50634

@mbellade

Description

@mbellade

Describe the bug

I created a Quarkus application using both Hibernate ORM and Reactive. I configured the blocking side with the default (unnamed) datasource pointing to the JDBC database URL, and a default (unnamed) ORM persistence unit. Then, I tried adding a named reactive datasource and a named reactive persistence unit using it. This resulted in an error when trying to start the application in dev mode, as the blocking persistence unit seems to look for a JDBC datasource with the same name as the configured reactive one.

From some initial troubleshooting, with the help of @lucamolteni, a couple of things stood out as possible causes: first, the check for whether to enable the default ORM persistence unit or not uses the HibernateOrmConfig#namedPersistenceUnits map, regardless if those PUs are blocking or reactive:

boolean enableDefaultPersistenceUnit = (defaultJdbcDataSource.isPresent()
&& hibernateOrmConfig.namedPersistenceUnits().isEmpty())
|| hibernateOrmConfig.defaultPersistenceUnit().isAnyPropertySet();

When trying to filter this map, based on the PU's configured datasource, we found that a blocking datasource with the same name as the configured reactive one was present in the JdbcDataSourceBuildItem list. In the Agroal extension, we noticed the configuration for the blocking default datasource was always returned here:

DataSourceJdbcBuildTimeConfig jdbcBuildTimeConfig = dataSourcesJdbcBuildTimeConfig
.dataSources().get(entry.getKey()).jdbc();
if (!jdbcBuildTimeConfig.enabled()) {
continue;
}

Even when looking up with the named reactive datasource name. This should be caused by the fact that DataSourcesJdbcBuildTimeConfig#dataSources is a map with default value, so if an entry for a specific key is not found the default datasource configuration is returned.

Expected behavior

The application works with both blocking and reactive PUs available as expected.

Actual behavior

Applications fails to start due to Agroal failing to find a named blocking datasource with the name of the configured reactive one.

How to Reproduce?

Here is a link to a Quarkus unit test case similar to the existing ones reproducing the problem.

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

No response

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

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions