mchack wrote:
Could someone provide a pointer/link as to the best mechanism to map DB
constraint violations from Hibernate (or ORM layer) back to the user
interface layer. I'm sure this has been solved but wasn't successful in
searching for an answer.

I'm not sure if this is the best way to do it, but I use a custom RequestCyleProcessor that extends WebRequestCycleProcessor.

It overrides #response(RuntimeException, RequestCycle) to check the RuntimeException for a ConstraintViolationException (call exception.getCause() recursively until you find one or it's null).

If it finds one, I send the user to a special error page.

The error will be vendor-specific, unfortunately.
I use something like this for MySQL:
ConstraintViolationException e = (ConstraintViolationException)t;
String detail = e.getSQLException().getMessage();
if (detail != null && detail.startsWith("Duplicate entry '")) {
    detail = detail.replaceAll(".*'(.*)'.*", "$1");
    detail = getString(
            "DuplicateEntry",
            new SingleStringMapModel("detail", detail)
    );
}

We do this for StaleObjectStateException too (use StaleObjectStateException#getEntityName() for your error message).

Regards,

Al

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to