Class OptimisticLockExceptionMapper
java.lang.Object
io.leandev.appfuse.error.mapper.OptimisticLockExceptionMapper
- All Implemented Interfaces:
ExceptionMapper<org.springframework.dao.OptimisticLockingFailureException>
public class OptimisticLockExceptionMapper
extends Object
implements ExceptionMapper<org.springframework.dao.OptimisticLockingFailureException>
樂觀鎖衝突映射器
處理 JPA @Version 樂觀鎖併發衝突,轉換為 RFC 7807 的 409 Conflict。
涵蓋 Spring 的 OptimisticLockingFailureException 及其 JPA 子型別
ObjectOptimisticLockingFailureException(@Version 版本過期時由 Hibernate 拋出)。
註冊順序要求:必須註冊在 DataAccessExceptionMapper 之前。
樂觀鎖例外是 DataAccessException 的子型別,若順序顛倒會被前者攔截、誤映為 500。
此映射器對未採用 @Version 的應用完全 inert——沒有版本欄位就不會拋出此例外。
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
OptimisticLockExceptionMapper
public OptimisticLockExceptionMapper()
-
-
Method Details
-
supports
Description copied from interface:ExceptionMapper檢查此 Mapper 是否支援給定的異常- Specified by:
supportsin interfaceExceptionMapper<org.springframework.dao.OptimisticLockingFailureException>- Parameters:
exception- 待檢查的異常- Returns:
- true 如果支援,否則 false
-
map
public org.springframework.http.ProblemDetail map(org.springframework.dao.OptimisticLockingFailureException ex) Description copied from interface:ExceptionMapper將異常轉換為 ProblemDetail (RFC 7807)- Specified by:
mapin interfaceExceptionMapper<org.springframework.dao.OptimisticLockingFailureException>- Parameters:
ex- 待轉換的異常- Returns:
- ProblemDetail 錯誤回應物件
-