-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
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:
Lines 891 to 893 in 4811438
| 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:
quarkus/extensions/agroal/deployment/src/main/java/io/quarkus/agroal/deployment/AgroalProcessor.java
Lines 309 to 313 in 2191f01
| 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