1
這是我Entity
:處理@Transactional的rollbackFor與@Where條款
@Entity
@Table(name = "example")
@Where(clause = "count >= 0")
public class Example {
@Column(name="count")
private Integer count;
//some code
}
這是我DML
操作:
@Transactional(rollbackFor = Exception.class)
public void updateService {
update();
}
void update(){
// findOne(Id) - if null throw Exception
// --count & save() //line 8
// findOne(Id) if null throw Exception //line 9
// --count & save()
// if something fails
throw new Exception("Exception thown.");
}
假設最初的count
價值0
爲Id
在D b。由於line 8
尚未提交,因此line 9
也將返回記錄。沒有exception
thrown
。它不會rollback
和更新數據庫,這不應該發生。任何人都可以幫忙,如果有任何hibernate
/JPA
解決方案存在這個。