我剛剛實現了JPA實體的唯一約束的異常處理。它正在按照我的要求工作,但在觸發時會將處理的異常轉儲到容器日誌文件。如何停止處理異常記錄?
- JPA實體由SLSB(服務外觀)管理。 ServiceFaçade由另一個SLSB調用,該SLSB提供基於JAX-RS的遠程處理功能。
- 在ServiceFaçade中,EntityManager操作包裝在try-catch-block中,檢測違反唯一約束的原因。然後它拋出一個自定義檢查
ApplicationException
。 - REST Bean捕獲
ApplicationException
並引發自定義未檢查BadRequestException
。 ExceptionMapper
將BadRequestException
輸出到遠程客戶端。
這一切都很好。我不明白的部分是:(處理)的異常記錄到日誌中容器的日誌文件(完整的長堆棧跟蹤):
[#|2010-09-29T18:49:39.185+0200|WARNING|glassfish3.0.1|org.eclipse.persistence.session.file:/Users/hank/NetBeansProjects/CoreServer/build/classes/_coreServerPersistenceUnit|_ThreadID=30;_ThreadName=Thread-1;|
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry....
....
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry....
和投擲BadRequestException:
[#|2010-09-29T18:49:39.336+0200|WARNING|glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=30;_ThreadName=Thread-1;|A system exception occurred during an invocation on EJB ShopperResource method public javax.ws.rs.core.Response mvs.gateway.ShopperResource.create(javax.xml.bind.JAXBElement)
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5119)
....
Caused by: mvs.api.exception.BadRequestException: mvs.api.exception.MvsCause: Field 'MSISDN' must be unique!
是這應該如何?我認爲自從我處理例外情況後,他們不會被轉儲到日誌中?