Duplicate
Details
Assignee
Diego PlentzDiego PlentzReporter
Florian RockFlorian RockPriority
Minor
Details
Details
Assignee
Diego Plentz
Diego PlentzReporter
Florian Rock
Florian RockPriority
Created November 6, 2007 at 1:06 AM
Updated March 21, 2011 at 7:05 PM
Resolved November 16, 2007 at 5:45 AM
> When using dialect org.hibernate.dialect.PostgreSQLDialect and a ConstraintViolationException is thrown, getConstraintName() does not get the right constraint name.
> It seems that there is something wrong with the ConstraintNameExtractor.
I still run into this problem.
lets take a look into the PostgresDialect:
------ BOF ------ private static ViolatedConstraintNameExtracter EXTRACTER = new TemplatedViolatedConstraintNameExtracter() {
public String extractConstraintName(SQLException sqle) {
try {
int sqlState = Integer.valueOf( JDBCExceptionHelper.extractSqlState(sqle)).intValue();
switch (sqlState) {
// CHECK VIOLATION
case 23514: return extractUsingTemplate("violates check constraint \"","\"", sqle.getMessage());
// UNIQUE VIOLATION
case 23505: return extractUsingTemplate("violates unique constraint \"","\"", sqle.getMessage());
// FOREIGN KEY VIOLATION
case 23503: return extractUsingTemplate("violates foreign key constraint \"","\"", sqle.getMessage());
// NOT NULL VIOLATION
case 23502: return extractUsingTemplate("null value in column \"","\" violates not-null constraint", sqle.getMessage());
// TODO: RESTRICT VIOLATION
case 23001: return null;
// ALL OTHER
default: return null;
}
} catch (NumberFormatException nfe) {
return null;
}
}
};
------ EOF ------
My problem ist that sqle is a BatchUpdateException and not the suspected PSQLExpection.
BatchUpdateException message doesn't contain the constraintName!
I sloved that by adding
"SQLException psqle = sqle.getNextException();"
and replace the "sqle.getMesage()" with "psqle.getMessage()"