我正在優化算法的過程中,我注意到Hibernate重複創建和釋放更新語句,而不是重複使用它們。這些都來自相同的查詢。Spring Hibernate,避免語句重複註冊和關閉
15:57:31,589 TRACE [.JdbcCoordinatorImpl]:371 - Registering statement [sql : 'update ...
15:57:31,591 TRACE [.JdbcCoordinatorImpl]:412 - Releasing statement [sql : 'update ...
15:57:31,592 TRACE [.JdbcCoordinatorImpl]:525 - Closing prepared statement [sql : 'update ...
15:57:31,592 TRACE [.JdbcCoordinatorImpl]:278 - Starting after statement execution processing [ON_CLOSE]
15:57:31,594 TRACE [.JdbcCoordinatorImpl]:371 - Registering statement [sql : 'update ...
15:57:31,595 TRACE [.JdbcCoordinatorImpl]:412 - Releasing statement [sql : 'update ...
15:57:31,596 TRACE [.JdbcCoordinatorImpl]:525 - Closing prepared statement [sql : 'update ...
15:57:31,596 TRACE [.JdbcCoordinatorImpl]:278 - Starting after statement execution processing [ON_CLOSE]
15:57:31,597 TRACE [.JdbcCoordinatorImpl]:371 - Registering statement [sql : 'update ...
15:57:31,599 TRACE [.JdbcCoordinatorImpl]:412 - Releasing statement [sql : 'update ...
15:57:31,600 TRACE [.JdbcCoordinatorImpl]:525 - Closing prepared statement [sql : 'update ...
15:57:31,601 TRACE [.JdbcCoordinatorImpl]:278 - Starting after statement execution processing [ON_CLOSE]
算法的主要方法有一個@Scope
和@Transactional
註解。預期的行爲是,如果出現任何問題,算法的更新是ROLLBACK
。
下面,算法使用@Service
,它有一個不同的@Scope
也是@Transactional
。該服務是使用Hibernate更新數據庫的服務,具有session.update(entity)
。該文檔說,默認情況下,嵌套事務如果存在,則重用該事務。
- 上面的肯定是正確的嗎?
- 範圍更改是否會產生問題?
- 如何讓Hibernate在事務處理過程中重複使用該語句?
感謝您的關注