0
服務器:WildFly10 JPA用的EclipseLink 2.6.3-M1 JavaEE7我爲什麼不能抓住這個EJBTransactionRolledbackException
我有以下EJB:
@Stateless
@LocalBean
public class HandleRollbackComponent {
private static Logger logger = Logger.getLogger(HandleRollbackComponent.class);
@EJB
private Tws14WSBatchChRequestsFacade tws14wsBatchChRequestsFacade;
public void doSomething() {
// first off go and fetch an instance of tws14 from the db
logger.debug("*************************************************");
logger.debug("1. First off go and fetch an instance of tws14 from the db");
String batchChReqId = "103";
Tws14WSBatchChRequests tws14wsBatchChRequests = tws14wsBatchChRequestsFacade.find(new BigDecimal(batchChReqId));
logger.debug("2. Found instance of tws14: " + tws14wsBatchChRequests);
logger.debug("2.1 CARD PLASTIC : " + tws14wsBatchChRequests.getCardPlastic());
try {
logger.debug("3. Now call a method that throws the EJBTrxnRollBackException....");
doSomethingThatThrowsEJBTransactionRolledbackException(tws14wsBatchChRequests);
logger.debug("---> This line should not be logged if exception was thrown....");
} catch (Exception e) {
logger.debug("5. Caught the exception....");
} finally {
logger.debug("6. Finally try and get a fresh instance from the db again...");
tws14wsBatchChRequests = tws14wsBatchChRequestsFacade.find(new BigDecimal(batchChReqId));
logger.debug("7. Was able to get instance from db: " + tws14wsBatchChRequests);
logger.debug("8. Try and update the instance of tws again...");
tws14wsBatchChRequestsFacade.edit(tws14wsBatchChRequests);
logger.debug("9. Could update the instance without problems.....");
logger.debug("10. Check the OrderCards value: " + tws14wsBatchChRequests.getOrderCards());
}
logger.debug("11. Done...");
}
public void doSomethingThatThrowsEJBTransactionRolledbackException(Tws14WSBatchChRequests tws14wsBatchChRequests) {
logger.debug("4. Set some invalid values on tws14 in an attempt to get exception thrown...");
tws14wsBatchChRequests.setOrderCards("N");
tws14wsBatchChRequests.setOrderCards("");
tws14wsBatchChRequests.setCardPlastic(null);
tws14wsBatchChRequestsFacade.edit(tws14wsBatchChRequests);
}
}
當我打電話DoSomething的(),這是我所看到的:
- 首先去,並從取tws14的一個實例分貝
- 實測值tws14的實例:za.co.fnds.persistence.entities.Tws14WSBatchChRequests [batchChRequestId = 103] 2.1 CARD PLASTIC:NBCRFLI_PIN
- 現在調用拋出EJBTrxnRollBackException的方法....
坐落於tws14一些無效的值,試圖獲取拋出異常......
--->如果異常被拋出此行應不會被記錄....
- 終於設法得到一個新的來自db的實例再次...
- 能夠從數據庫獲取實例:za.co.fnds.persistence.entities.Tws14WSBatchChRequests [batchChRequestId = 103]
- 嘗試和更新再次交易平臺的情況下...
- 可以更新沒有問題的情況下.....
- 檢查OrderCards值:
- 完成...
我的問題是,爲什麼在程序不打算進入catch子句,因爲我的日誌表明使用javax .validation.ConstraintViolationException是拋出ñ。爲什麼上面的大膽日誌仍然顯示?我錯過了什麼?有沒有一種方法我應該在EJB中處理這個程序結構?