How do you find out what Exception caused the CDI Transaction Rollback?

前端 未结 2 1231
礼貌的吻别
礼貌的吻别 2021-02-10 03:13

We are using CDI with CMT (container managed transactions) to connect to the database in the web app and mark methods called from the front-end that require a transaction with:<

2条回答
  •  逝去的感伤
    2021-02-10 04:09

    The TransactionalException is thrown at the commit time, i.e. after your code has been fully executed. Since the transaction is marked for rollback, commit cannot take place and the exception is thrown.

    However, the transaction was marked for rollback sometime during the execution. I assume you do not mark it for rollback manually, therefore an exception must have been thrown. The exception is either a RuntimeException or it is annotated with @ApplicationException(rollback = true). Since you don't get this exception, the exception must have been caught somewhere. Are you sure you do not catch exceptions thrown from a business method in your code?

    To answer the question... No, I don't think it is possible to rethrow the original exception, because it is thrown at different time and place.

提交回复
热议问题