From bf3159f5c313e846897520daa87c5ad25b4fc191 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Fri, 1 May 2020 16:22:44 +0100 Subject: [PATCH] Set Hibernate ORM connection handling strategy to BEFORE_TRANSACTION_COMPLETION --- .../runtime/boot/FastBootMetadataBuilder.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 9aced35f01c13..f25513ba2e933 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 @@ -64,6 +64,7 @@ import org.hibernate.jpa.internal.util.LogHelper; import org.hibernate.jpa.internal.util.PersistenceUnitTransactionTypeHelper; import org.hibernate.jpa.spi.IdentifierGeneratorStrategyProvider; +import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl; import org.hibernate.service.Service; @@ -241,6 +242,21 @@ 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. + * + * @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); + } + } + if (readBooleanConfigurationValue(cfg, WRAP_RESULT_SETS)) { LOG.warn("Wrapping result sets is not supported. Setting " + WRAP_RESULT_SETS + " to false."); }