[英]How to validate objects before insert/update/delete using mybatis on dao layer
[英]I executed the mybatis update method of the dao layer, but the database is not updated
當我運行junit4測試時,我發現mybatis的方法已成功更新,但是數據庫沒有更新的記錄,但是在執行方法下面有一個while循環執行邏輯,這是因為該方法尚未被執行被處決了嗎? 但是當我刪除了while循環並在mysql中進行了更新。
public void executeMethod(Long id) {
UserMapper.updateById(id);
while(conditions) {
// some business
}
}
一種可能的原因是在檢查數據庫時未提交事務。
例如,如果用@Transactional
注釋executeMethod
,則在輸入方法之前先注視事務,然后在executeMethod
完成后executeMethod
。 因此,如果要在控制流離開executeMethod
之前檢查數據庫,則更改尚未提交,因此當您從另一個事務查詢數據庫時這些更改不可見。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.