How to catch SqlIntegrityConstraint violation exception

1.2k views Asked by At

I have a scenario where user submits an order for a fund and a security. And if he submits the another order with same fund and security DB throws back SqlIntegrityVoilationException with error code ora-00001.

But my question here is this exception is not getting caught under java.sql.sqlintegrityconstraintviolationexception. I am able to catch this under org.springframework.dao.DataIntegrityViolationException, but I am not able to retrieve the error code (to check for ora-00001).

Anybody has any ideas how to catch that exception and retrieve the error code to check so that I can put back a custom error message like "you cannot submit a dup order for same fund and security combination".

EDIT

catch (SQLException e) {
      ex = e; inOrder.setActionMessage(ex.getMessage()); 
}
catch (DataIntegrityViolationException e) {
      ex = e; inOrder.setActionMessage(ex.getMessage()); 
}
0

There are 0 answers