我尝试保留实体列表:
for (Charge charge : charges) {
try {
Charge savedCharge = saveCharge(charge);
}catch (DataAccessException e){
log.error(e.getMessage());
}
}
public Charge saveCharge(Charge charge){
return chargesRepository.save(charge);
}
有时候我会出胎:
Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: the limitation of uniqueness has been violated
我需要抓住这个机会。我该怎么办?
答案 0 :(得分:0)
您将其作为任何异常捕获。但是我建议您宁愿从Spring框架中了解DataIntegrityViolationException
,因为Spring已经将SQL异常转换为更具体的异常:
try {
Charge savedCharge = saveCharge(charge);
} catch (DataIntegrityViolationException e) {
log.error(e.getMessage());
// more error handling actions
} // more catch clauses