Skip to content

Commit

Permalink
Set Hibernate ORM connection handling strategy to BEFORE_TRANSACTION_…
Browse files Browse the repository at this point in the history
…COMPLETION
  • Loading branch information
Sanne authored and yrodiere committed Jan 21, 2021
1 parent 25798f3 commit bf3159f
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
}
Expand Down

0 comments on commit bf3159f

Please sign in to comment.