This isn't the answer, but could be a step in the right direction:
I wrap hibernate in spring, and spring rethrows hibernate exceptions as its own. One that you are looking for would be the spring exception "DataIntegrityViolationException". I actually catch this one to do just as you say and make easy error messages to the user (I actually use an annotation and aspect to make it simple for me to make easy error messages by just annotating a service method call which maps the error key to the thrown exception).
I'm guessing Spring isn't doing anything vendor specific to do this, so you may want to dig into the guts of spring to see how they do it.
For the record, the fully qualified exception I'm catching is:
org.springframework.dao.DataIntegrityViolationException
|