I\'m using hibernate to insert to a mysql table on which all columns are defined as not null. It has a unique primary key and another unique index on several columns.
I\
you can get the Constain name directly from Hibernate's exception type. use
getConstraintName
property to get DB constrain name.
} catch (ConstraintViolationException conEx) {
if (conEx.getConstraintName().contains("PROJECT_UK")) {
//TODO Project Entity is violating it's constrain
I've used contains because I want this app to run on multiple DB Schemas. By default getConstraintName comes with DB name like
MyDBName.ConstrainName