我在設定資料庫復制時修改資料時遇到問題
在資料庫復制之前,我得到了我想要修改repository.findById()的資料,然后我修改了資料。但我意識到這repository.findById()是設定@Transactional(readOnly = true)的,SimpleJpaRepository.java即使我在我的服務中使用 @Transactional 或repository.save()
除了在存盤庫中為 findById 創建自定義方法之外,還有其他方法可以強制findById()通過寫入連接進行連接嗎?
) 我解決了我的問題!我想使用臟檢查來修改資料,我意識到我關于 EntityManagerFactory 的設定有問題,我用 spring.io 中的檔案修復了它(https://docs.spring.io/spring-data/jpa/docs/ current-SNAPSHOT/reference/html/#reference ) 我曾多次嘗試與許多其他開發人員一起發布,但他們對我不起作用,但確實如此。謝謝你給我答案??
uj5u.com熱心網友回復:
請參閱
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#transactions
第 5.7.1 節。更具體的事務查詢方法
它說@Modifying注解可以用于覆寫事務配置
Typically you will use the readOnly flag set to true as most of the query methods will be reading ones. In contrast to that deleteInactiveUsers() makes use of the @Modifying annotation and overrides the transaction configuration. Thus the method will be executed with readOnly flag set to false.
uj5u.com熱心網友回復:
你不需要改變那個標志!
- 查找資料
- 編輯資料
- 使用@Modifying 呼叫JPA repository.save(newData) 方法將編輯后的資料保存到資料庫中
IE
@Transactional
@Modifying
@Query(value = "UPDATE user SET points = points ?1 WHERE id = ?2", nativeQuery = true)
int increasePoints(int points, Long id);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/464628.html
