Skip to content

Commit 18c3273

Browse files
authored
Merge pull request quarkusio#47910 from yrodiere/allow-unsupported-overrides
Allow "unsupported properties" set in the Hibernate ORM/Reactive extension to override Quarkus' own values
2 parents 330049e + 9541608 commit 18c3273

File tree

6 files changed

+60
-38
lines changed

6 files changed

+60
-38
lines changed

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,21 @@ public class UnsupportedPropertiesTest {
5151
// This is just to test a property set at build time
5252
.overrideConfigKey("quarkus.hibernate-orm.unsupported-properties.\"hibernate.some.unknown.key.static-and-runtime\"",
5353
"some-value-1")
54-
// This is just to test a property set at runtime, which which would not be available during the build
54+
// This is just to test a property set at runtime, which would not be available during the build
5555
// (or even during static init with native applications).
5656
.overrideRuntimeConfigKey(
5757
"quarkus.hibernate-orm.unsupported-properties.\"hibernate.some.unknown.key.runtime-only\"",
5858
"some-value-2")
59-
// This should be ignored with a warning
59+
// This overrides a property set by Quarkus, and thus should trigger an additional warning
6060
.overrideConfigKey(
6161
"quarkus.hibernate-orm.unsupported-properties.\"" + AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION
6262
+ "\"",
63-
"drop-and-create")
63+
// Deliberately using the Hibernate-native name instead of the JPA one that Quarkus uses
64+
// This allows us to check the override did happen
65+
"create-drop")
66+
.overrideConfigKey(
67+
"quarkus.hibernate-orm.unsupported-properties.\"" + AvailableSettings.ORDER_UPDATES + "\"",
68+
"false")
6469
// Expect warnings on startup
6570
.setLogRecordPredicate(record -> FastBootHibernatePersistenceProvider.class.getName().equals(record.getLoggerName())
6671
&& record.getLevel().intValue() >= Level.WARNING.intValue())
@@ -75,17 +80,18 @@ public class UnsupportedPropertiesTest {
7580
"Consider using a supported configuration property",
7681
"make sure to file a feature request so that a supported configuration property can be added to Quarkus")
7782
.contains(AvailableSettings.ORDER_INSERTS, AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION,
83+
AvailableSettings.ORDER_UPDATES,
7884
"hibernate.some.unknown.key.static-and-runtime", "hibernate.some.unknown.key.runtime-only")
7985
// We should not log property values, that could be a security breach for some properties.
8086
.doesNotContain("some-value"));
8187
assertion.element(1).satisfies(record -> assertThat(LOG_FORMATTER.formatMessage(record))
8288
.contains(
83-
"Persistence-unit [<default>] sets property '"
84-
+ AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION
85-
+ "' to a custom value through 'quarkus.hibernate-orm.unsupported-properties.\""
86-
+ AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION + "\"'",
87-
"Quarkus already set that property independently",
88-
"The custom value will be ignored"));
89+
"Persistence-unit [<default>] sets unsupported properties that override Quarkus' own settings",
90+
"These properties may break assumptions in Quarkus code and cause malfunctions",
91+
"make sure to file a feature request or bug report so that a solution can be implemented in Quarkus")
92+
.contains(AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, AvailableSettings.ORDER_UPDATES)
93+
.doesNotContain(AvailableSettings.ORDER_INSERTS, "hibernate.some.unknown.key.static-and-runtime",
94+
"hibernate.some.unknown.key.runtime-only"));
8995
});
9096

9197
@Inject
@@ -106,7 +112,9 @@ public void testPropertiesPropagatedToStaticInit() {
106112
@Test
107113
public void testPropertiesPropagatedToRuntimeInit() {
108114
assertThat(emf.getProperties())
109-
.contains(entry("hibernate.order_inserts", "true"),
115+
.contains(entry(AvailableSettings.ORDER_INSERTS, "true"),
116+
entry(AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, "create-drop"),
117+
entry(AvailableSettings.ORDER_UPDATES, "false"),
110118
// Also test a property that Quarkus cannot possibly know about
111119
entry("hibernate.some.unknown.key.static-and-runtime", "some-value-1"),
112120
entry("hibernate.some.unknown.key.runtime-only", "some-value-2"));

extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,23 @@ private RuntimeSettings buildRuntimeSettings(String persistenceUnitName, Recorde
242242
persistenceUnitName,
243243
persistenceUnitConfig.unsupportedProperties().keySet());
244244
}
245+
Set<String> overriddenProperties = new HashSet<>();
245246
for (Map.Entry<String, String> entry : persistenceUnitConfig.unsupportedProperties().entrySet()) {
246247
var key = entry.getKey();
247-
if (runtimeSettingsBuilder.get(key) != null) {
248-
log.warnf("Persistence-unit [%s] sets property '%s' to a custom value through '%s',"
249-
+ " but Quarkus already set that property independently."
250-
+ " The custom value will be ignored.",
251-
persistenceUnitName, key,
252-
HibernateOrmRuntimeConfig.puPropertyKey(persistenceUnitName, "unsupported-properties.\"" + key + "\""));
253-
continue;
248+
var value = runtimeSettingsBuilder.get(key);
249+
if (value != null && !(value instanceof String stringValue && stringValue.isBlank())) {
250+
overriddenProperties.add(key);
254251
}
255252
runtimeSettingsBuilder.put(entry.getKey(), entry.getValue());
256253
}
254+
if (!overriddenProperties.isEmpty()) {
255+
log.warnf("Persistence-unit [%s] sets unsupported properties that override Quarkus' own settings."
256+
+ " These properties may break assumptions in Quarkus code and cause malfunctions."
257+
+ " If this override is absolutely necessary, make sure to file a feature request or bug report so that a solution can be implemented in Quarkus."
258+
+ " Unsupported properties that override Quarkus' own settings: %s",
259+
persistenceUnitName,
260+
overriddenProperties);
261+
}
257262

258263
var databaseOrmCompatibilityVersion = buildTimeSettings.getSource().getDatabaseOrmCompatibilityVersion();
259264
var databaseOrmCompatibilitySettings = buildTimeSettings.getDatabaseOrmCompatibilitySettings();

extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,9 @@ private BuildTimeSettings createBuildTimeSettings(QuarkusPersistenceUnitDefiniti
205205
.getQuarkusConfigUnsupportedProperties();
206206
Map<String, Object> allSettings = new HashMap<>(quarkusConfigSettings);
207207

208-
// Ignore properties that were already set by Quarkus;
209-
// we'll log a warning about those on startup.
208+
// We'll log warnings about unsupported properties and overrides on startup.
210209
// (see io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider.buildRuntimeSettings)
211-
quarkusConfigUnsupportedProperties.forEach(allSettings::putIfAbsent);
210+
allSettings.putAll(quarkusConfigUnsupportedProperties);
212211

213212
var databaseOrmCompatibilityVersion = puDefinition.getConfig().getDatabaseOrmCompatibilityVersion();
214213
Map<String, String> appliedDatabaseOrmCompatibilitySettings = new HashMap<>();

extensions/hibernate-reactive/deployment/src/test/java/io/quarkus/hibernate/reactive/config/unsupportedproperties/UnsupportedPropertiesTest.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ public class UnsupportedPropertiesTest {
4949
.overrideRuntimeConfigKey(
5050
"quarkus.hibernate-orm.unsupported-properties.\"hibernate.some.unknown.key.runtime-only\"",
5151
"some-value-2")
52-
// This should be ignored with a warning
52+
// This overrides a property set by Quarkus, and thus should trigger an additional warning
5353
.overrideConfigKey(
5454
"quarkus.hibernate-orm.unsupported-properties.\"" + AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION
5555
+ "\"",
56-
"drop-and-create")
56+
// Deliberately using the Hibernate-native name instead of the JPA one that Quarkus uses
57+
// This allows us to check the override did happen
58+
"create-drop")
59+
.overrideConfigKey(
60+
"quarkus.hibernate-orm.unsupported-properties.\"" + AvailableSettings.ORDER_UPDATES + "\"",
61+
"false")
5762
// Expect warnings on startup
5863
.setLogRecordPredicate(
5964
record -> FastBootHibernateReactivePersistenceProvider.class.getName().equals(record.getLoggerName())
@@ -74,12 +79,12 @@ record -> FastBootHibernateReactivePersistenceProvider.class.getName().equals(re
7479
.doesNotContain("some-value"));
7580
assertion.element(1).satisfies(record -> assertThat(LOG_FORMATTER.formatMessage(record))
7681
.contains(
77-
"Persistence-unit [default-reactive] sets property '"
78-
+ AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION
79-
+ "' to a custom value through 'quarkus.hibernate-orm.unsupported-properties.\""
80-
+ AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION + "\"'",
81-
"Quarkus already set that property independently",
82-
"The custom value will be ignored"));
82+
"Persistence-unit [default-reactive] sets unsupported properties that override Quarkus' own settings",
83+
"These properties may break assumptions in Quarkus code and cause malfunctions",
84+
"make sure to file a feature request or bug report so that a solution can be implemented in Quarkus")
85+
.contains(AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION)
86+
.doesNotContain(AvailableSettings.ORDER_INSERTS, "hibernate.some.unknown.key.static-and-runtime",
87+
"hibernate.some.unknown.key.runtime-only"));
8388
});
8489

8590
@Inject
@@ -104,7 +109,9 @@ public void testPropertiesPropagatedToRuntimeInit() throws IllegalAccessExceptio
104109
// All good, you can look now.
105110

106111
assertThat(ormSessionFactory.getProperties())
107-
.contains(entry("hibernate.order_inserts", "true"),
112+
.contains(entry(AvailableSettings.ORDER_INSERTS, "true"),
113+
entry(AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, "create-drop"),
114+
entry(AvailableSettings.ORDER_UPDATES, "false"),
108115
// Also test a property that Quarkus cannot possibly know about
109116
entry("hibernate.some.unknown.key.static-and-runtime", "some-value-1"),
110117
entry("hibernate.some.unknown.key.runtime-only", "some-value-2"));

extensions/hibernate-reactive/deployment/src/test/resources/application.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ quarkus.datasource.username=hibernate_orm_test
33
quarkus.datasource.password=hibernate_orm_test
44
quarkus.datasource.reactive=true
55
quarkus.datasource.reactive.url=${postgres.reactive.url}
6-
quarkus.postgres_blvertx-reactive:postgresql://localhost:5431/hibernate_orm_test"
76

87
# Hibernate config
98
#quarkus.hibernate-orm.log.sql=true

extensions/hibernate-reactive/runtime/src/main/java/io/quarkus/hibernate/reactive/runtime/FastBootHibernateReactivePersistenceProvider.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,23 @@ private EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String
189189
persistenceUnitName,
190190
puConfig.unsupportedProperties().keySet());
191191
}
192+
Set<String> overriddenProperties = new HashSet<>();
192193
for (Map.Entry<String, String> entry : puConfig.unsupportedProperties().entrySet()) {
193194
var key = entry.getKey();
194-
if (runtimeSettingsBuilder.get(key) != null) {
195-
log.warnf("Persistence-unit [%s] sets property '%s' to a custom value through '%s',"
196-
+ " but Quarkus already set that property independently."
197-
+ " The custom value will be ignored.",
198-
persistenceUnitName, key,
199-
HibernateOrmRuntimeConfig.puPropertyKey(persistenceUnit.getConfigurationName(),
200-
"unsupported-properties.\"" + key + "\""));
201-
continue;
195+
var value = runtimeSettingsBuilder.get(key);
196+
if (value != null && !(value instanceof String stringValue && stringValue.isBlank())) {
197+
overriddenProperties.add(key);
202198
}
203199
runtimeSettingsBuilder.put(entry.getKey(), entry.getValue());
204200
}
201+
if (!overriddenProperties.isEmpty()) {
202+
log.warnf("Persistence-unit [%s] sets unsupported properties that override Quarkus' own settings."
203+
+ " These properties may break assumptions in Quarkus code and cause malfunctions."
204+
+ " If this override is absolutely necessary, make sure to file a feature request or bug report so that a solution can be implemented in Quarkus."
205+
+ " Unsupported properties that override Quarkus' own settings: %s",
206+
persistenceUnitName,
207+
overriddenProperties);
208+
}
205209

206210
RuntimeSettings runtimeSettings = runtimeSettingsBuilder.build();
207211

0 commit comments

Comments
 (0)