tsh
tsh

Reputation: 303

I'm throwing an AccessDeniedException before method execution, but get an EJBException

I'm using AspectJ to do access checks before the execution of methods inside an EJB environment and I'm therefore intercepting the control flow before methods with an around advice (I know that there are EJB-Interceptors, too). If the access check fails, I'm throwing an AccessDeniedException. Unfortunately what I get is an EJBException with the cause "AccessDeniedException". How can I circumvent this behaviour?

Upvotes: 1

Views: 116

Answers (1)

Mike Braun
Mike Braun

Reputation: 3769

This is caused by the difference between system and application exceptions. These correspond roughly to non-checked and checked exceptions.

Each of them has certain properties. The system exception will be wrapped in an EJBException, the bean(s) in which the exception occurred will be destroyed, and any pending transaction will be rolled back.

What people often want is a non-checked exception, that only does a rollback.

You can create such one by using the @ApplicationException on one of your own exception types (can be non-checked) and then setting the annotation's attributes accordingly.

Upvotes: 2

Related Questions