Skip to content

Commit 6f0aa97

Browse files
committed
Improve error message for missing datasource at build time with an implicit persistence unit
1 parent 963a2bf commit 6f0aa97

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,15 @@ private void handleHibernateORMWithNoPersistenceXml(
914914
&& !defaultJdbcDataSource.isPresent()) {
915915
String persistenceUnitName = PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME;
916916
String dataSourceName = DataSourceUtil.DEFAULT_DATASOURCE_NAME;
917-
throw PersistenceUnitUtil.unableToFindDataSource(persistenceUnitName, dataSourceName,
918-
DataSourceUtil.dataSourceNotConfigured(dataSourceName));
917+
var cause = DataSourceUtil.dataSourceNotConfigured(dataSourceName);
918+
throw new ConfigurationException(String.format(Locale.ROOT,
919+
"Persistence unit '%s' defines entities %s, but its datasource '%s' cannot be found: %s"
920+
+ " Alternatively, disable Hibernate ORM by setting '%s=false', and the entities will be ignored.",
921+
persistenceUnitName, modelClassesAndPackagesForDefaultPersistenceUnit,
922+
dataSourceName,
923+
cause.getMessage(),
924+
HibernateOrmRuntimeConfig.extensionPropertyKey("enabled")),
925+
cause);
919926
}
920927

921928
for (Entry<String, HibernateOrmConfigPersistenceUnit> persistenceUnitEntry : hibernateOrmConfig.namedPersistenceUnits()

extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/config/NoDatasourceTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ public class NoDatasourceTest {
2020
.overrideConfigKey("quarkus.datasource.jdbc", "false")
2121
.assertException(t -> assertThat(t)
2222
.hasMessageContainingAll(
23-
"Unable to find datasource '<default>' for persistence unit '<default>'",
23+
"Persistence unit '<default>' defines entities [" + MyEntity.class.getName()
24+
+ "], but its datasource '<default>' cannot be found",
2425
"Datasource '<default>' is not configured.",
2526
"To solve this, configure datasource '<default>'",
26-
"Refer to https://quarkus.io/guides/datasource for guidance."));
27+
"Refer to https://quarkus.io/guides/datasource for guidance.",
28+
"Alternatively, disable Hibernate ORM by setting 'quarkus.hibernate-orm.enabled=false', and the entities will be ignored"));
2729

2830
@Test
2931
public void test() {

0 commit comments

Comments
 (0)