[英]Hibernate vs Spring connection acquisition strategy
I can't understand how can Hibernate delay the connection aquisition if Spring decides to aquire it before.
該決定由事務管理器做出,因此可能由JpaTransactionManager/HibernateTransactionManager
Hibernate 5.2.0 引入新屬性hibernate.connection.provider_disables_autocommit
有了這個 Hibernate 可以延遲數據庫連接獲取,直到有 JDBC 語句要執行。 否則進入@Transactional服務方法時獲取數據庫連接。
So to allow Spring wires this property into the JPATransactionManager during the setup of spring context you have to set this property in your application.properties/yaml --> spring.jpa.properties.hibernate.connection.provider_disables_autocommit
執行此操作所需的最后一件事->在連接池提供程序上將自動提交設置為 false(默認情況下 HikariCP 自 Spring 啟動 2) spring.datasource.hikari.auto-commit=false
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.