vladmihalcea / hypersistence-optimizer

Hypersistence Optimizer allows you to get the most out of JPA and Hibernate. By scanning your application configuration and mappings, Hypersistence Optimizer can tell you what changes you need to do to speed up your data access layer.
https://vladmihalcea.com/hypersistence-optimizer/
Apache License 2.0
306 stars 43 forks source link

hibernate.connection.handling_mode detection #200

Closed willome closed 1 year ago

willome commented 1 year ago

Hi Vlad,

Even if I am not sure about that, the hibernate hibernate.connection.handling_mode should be set to DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION for non JTA environments, especially with a spring application.

SpringFramework keeps the legacy mode (really ?) and we also could set the JpaDialect like this ((HibernateJpaVendorAdapter) bean).getJpaDialect().setPrepareConnection(false)

I really do not know if it is a good idea or not, but according to this old thread, it could be an improvement.

And with a spring application, that was the only way to make the RoutingDataSource effectively working (see https://stackoverflow.com/questions/68012475/how-to-do-database-routing-in-read-only-and-read-write-with-spring).

vladmihalcea commented 1 year ago

For a Spring app that uses the default JpaTransactionManager, the default connection release mode should be the right one, at least on Hibernate 5.

Related to the setPrepareConnection, the default is true, meaning that you can set the isolation level and the read-only flag on the Connection.

Setting this to false is not really an improvement, in my opinion.

In my transaction routing example, I didn't have to set this property, so maybe it's not needed anymore.