tags:

views:

13

answers:

1

I would like to be able to extract the entity and property from the ConstraintViolationException message in a rdbms neutral way... Can this be done ? if so how ?

A: 

Look into the hibernate source code: org.hibernate.exception.SQLStateConverter translates the SQLException.SQLState into the appropriate hibernate exception. SQLState is the only vendor-independent normalized data you have to find out the error cause. Java API documents it can follow one of two standards for error codes and messages... but there is no standard for specifying error detail.

So I think no, it can't be done, unless you have all rdbms at hand to test and interpret the error message strings yourself.

Moritz Both
I have looked at SQLExcecptionConverter but one trap is that its a pain to decorate with your impl if you wish to decoate the dialect specific one that HIbernate figures out. Yes I have seen the Environment.key to put the fq classname of my own but then i lose the dialect one. Its also hard to update Settings as the setters are package private which means one needs to do some reflection hacking.
mP