You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider disabling auto-commit when wiring connection pool configs and setting hibernate.connection.provider_disables_autocommit for resource-local transactions #9261
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:
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:
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).
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.