try {
//perform a transaction operation here, perhaps a delete
} catch (EJBTransactionRolledbackException e) {
Throwable t = e.getCause();
while ((t != null) && !(t instanceof ConstraintViolationException)) {
t = t.getCause();
}
if (t instanceof ConstraintViolationException) {}
}
As you can see we catch EJBTransactionRolledbackException, why not ConstraintViolationException? Trust me it will not work because that exception is already wrapped by the container, so to be able to process it we need to unwrap it again.
0 nhận xét:
Đăng nhận xét