我試圖攔截一個樂觀鎖例外并拋出另一個例外,但在我的情況下它不起作用,例外被捕獲但我的控制臺中仍然有錯誤樂觀鎖。
//我的道
public Entity getEntitieSimple(...) throws CustomException{
Entity entity="my select";
}
//我的服務
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public Entity recupererEntity() throws CustomException{
Entity entity =null;
try {
entity = dao.getEntitieSimple(...);
}catch (Exception exec){
throw new CustomException("custom message");
}
return entity;
}
@Transactional(propagation = Propagation.REQUIRED)
public void myUpdate() throws HibernateException{
try {
// entity update here
}catch (HibernateException exec){
log.error("OPTIMISTIC: " exec.getMessage());
throw new HibernateException("optimi update");
}
}
捕獲例外后,我會收到此錯誤:
ERROR - 29-09-2022 09:59:44.204 - http-nio-8090-exec-5 - 3933807 - null - c:96e7d7ca8f7d5637 - org.hibernate.internal.ExceptionMapperStandardImpl - HHH000346: Error during managed flush [Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [com.apicil.cosy.dop.domain.impl.Entity#1420]]
uj5u.com熱心網友回復:
你必須抓住ConcurrencyFailureException
private void updateStatus(UpdateOrderDto dto, OrdersStatusUpdaterService self) {
try {
updateStatusHelper(dto, self);
} catch (ConcurrencyFailureException ex) {
log.error("Concurrent modification error. Will try next time. orderId={}", dto.getId(), ex);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/513219.html
標籤:弹簧靴休眠
