From d39f754dcf3aa4d53c1fa19712f5909596242f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Wed, 13 Jan 2021 11:16:27 +0100 Subject: [PATCH] Simplify connection handling setup and add a note about #7242 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT, on top of being less efficient, also leads to resource leaks (that are caught by Agroal, but still). Signed-off-by: Yoann Rodière --- .../orm/runtime/boot/FastBootMetadataBuilder.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java index f25513ba2e933..44ea98d385395 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java @@ -242,20 +242,18 @@ private MergedSettings mergeSettings(PersistenceUnitDescriptor persistenceUnit) //Agroal already does disable auto-commit, so Hibernate ORM should trust that: cfg.put(AvailableSettings.CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT, Boolean.TRUE.toString()); - /** + /* * Set CONNECTION_HANDLING to DELAYED_ACQUISITION_AND_RELEASE_BEFORE_TRANSACTION_COMPLETION * as it generally performs better, at no known drawbacks. * This is a new mode in Hibernate ORM, it might become the default in the future. * + * Note: other connection handling modes lead to leaked resources, statements in particular. + * See https://github.com/quarkusio/quarkus/issues/7242, https://github.com/quarkusio/quarkus/issues/13273 + * * @see org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode */ - { - final Object explicitSetting = cfg.get(AvailableSettings.CONNECTION_HANDLING); - if (explicitSetting == null) { - cfg.put(AvailableSettings.CONNECTION_HANDLING, - PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_BEFORE_TRANSACTION_COMPLETION); - } - } + cfg.putIfAbsent(AvailableSettings.CONNECTION_HANDLING, + PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_BEFORE_TRANSACTION_COMPLETION); if (readBooleanConfigurationValue(cfg, WRAP_RESULT_SETS)) { LOG.warn("Wrapping result sets is not supported. Setting " + WRAP_RESULT_SETS + " to false.");