Well...no one came forward with a "hibernate kosher" way of handling this...so I just parsed the "cause" string.
For the benefit of others...here's my makeTransient method:
Code:
public void makeTransient(Metric metric) throws Exception
{
try {
HibernateUtil.getSession().delete(metric);
HibernateUtil.getSession().flush();
} catch (HibernateException ex) {
HibernateUtil.rollbackTransaction();
if (parseException.isIntegrityConstraintViolation(ex)) {
log.info("Integrity constraint violated");
throw new ChildRecordsExistException(ex);
} else {
log.info("no integrity constraint violated");
throw new InfrastructureException(ex);
}
}
}
I created a class called "parseException" to have a set of static methods to perform operations on the exceptions. So far it just has the method used above, that determines whether the exception is caused by an oracle constraint violation.
Code:
/**
* Returns true if Oracle error ORA-02292 is part of the cause passed in
* Constants.INTEGRITY_CONSTRAINT_VIOLATION = ORA-02292
* @param cause
* @return
*/
public static boolean isIntegrityConstraintViolation(HibernateException ex) {
boolean value = false;
String cause = ex.getCause().toString();
if (cause.indexOf(Constants.INTEGRITY_CONSTRAINT_VIOLATION) > 0) {
return true;
} else {
return false;
}
}