Skip to content

Consider disabling auto-commit when wiring connection pool configs and setting hibernate.connection.provider_disables_autocommit for resource-local transactions #9261

@vladmihalcea

Description

@vladmihalcea

As I explained in this article, there is a new optimization option we introduced in Hibernate 5.2.10 which makes a lot of sense for most Spring applications:

<property name="hibernate.connection.provider_disables_autocommit" valaue="true"/>

With this property in place, Hibernate can delay the database connection acquisition until there is a JDBC Statement to execute. This is very convenient, as otherwise, the database connection is acquired when entering the @Transactional service method.

Now, to benefit from this optimization, you'd have to do 2 things:

  1. To make sure you disable auto-commit when wiring up the connection pool Spring bean. For instance, HickariCP allows you to set it via HikariConfiguartion#setAutoCommit(false).
  2. To set up the hibernate.connection.provider_disables_autocommit when wiring a JpaTransactionManager or HibernateTranscationManager.

Enabling auto-commit by default is unlikely to break anything since, even if you don't do it, Hibernate does that anyway when starting a JPA Transaction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions