Hi Ray,
I realize that I'd really asked a Java question here but this topic still could be some easy credits for someone :)
getRootCause() returns a Throwable - which I know is a ConstraintViolationException thanks to my IDE. What I really wanted to do is set up my catch block to inspect the returned throwable object determine if it's a ConstraintViolationException and then use the getNextException() method of the ConstraintViolationException iterate through the SQL exceptions.
So this is what I did .. (code borrowed from
OnJava)
Code:
} catch (DataAccessException e) {
Throwable t = e.getMostSpecificCause();
if (t instanceof ConstraintViolationException) {
SQLException ex = (SQLException) t.getCause();
while(ex != null){
while(t != null) {
System.out.println("Cause:" + t);
t = t.getCause();
}
ex.printStackTrace();
ex = ex.getNextException();
}
}
The thing is the error message was still just as cryptic and had been bubbled up to the original DataAccessException (actually a DataIntegrityViolationException) which reads:
Error for batch element #1: Assignment of a NULL value to a NOT NULL column "TBSPACEID=2, TABLEID=270, COLNO=1" is not allowed.
Is there a way to get the error to tell me the human friendly table
name and column
name that failed?
Thanks again!