I just use following code to try to get the reason for exception and then throw my application exception based on it. I remember here, months back, on this forum there was an example to find the exact cause of exception - but I am not able to find the link/post.
Code:
String exMsg = e.getMessage();
System.out.println("exceptionMessage = " + exMsg);
// Will this naming convention stay same
// for all future releases of hibernate?
if ( (exMsg != null) && (exMsg.indexOf( "org.hibernate.exception.ConstraintViolationException" ) != -1) ) {
exMsg = "The Code entered already exists, please enter a unique Code.";
}
throw new MyApplicationException( exMsg );