it is possible to get to the causes.
For example code like this:
Code:
try{
Child c = (Child) s.createQuery("from Child c where c.id = 2").uniqueResult();
s.delete(c);
s.flush();
}catch( RuntimeException e ){
System.out.println("e = " + e);
Throwable ne = e;
while( ne != null){
if( ne instanceof SQLException ){
SQLException sqle = (SQLException) ne;
ne = sqle.getNextException();
System.out.println("sqle = " + sqle.getMessage());
}else{
ne = ne.getCause();
}
}
}
Would print out
e = org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
sqle = Batch entry 0 delete from Child where id= was aborted. Call getNextException() to see the cause.
code=0
state=null
sqle = ERROR: update or delete on "child" violates foreign key constraint "association_child_id_fkey" on "association"
code=0
state=23503