You can annotate your checked exception with the annotation: @ApplicationException(rollback = true).
e.g.:
@ApplicationException(rollback = true)
public class MyApplicationException extends Exception{
}
This will mark the current transaction for rollback.
Edit:
I do not want to use a exception to execute a rollback because I cant response with a http status code
Other alternative is to explicitly marks the transaction for rollback using the SessionContext.setRollbackOnly() method. I don't know your app design, but an example would be:
@Stateless
public class MyBean(){
@Resource
private SessionContext ctx;
public void doSomething() {
try {
//code that sends a mail
} catch (Exception e) {
ctx.setRollbackOnly(); //the transaction will not commit
//log exception
}
}
}