From f1439b560142dd81d83c6142acb27956459e922f Mon Sep 17 00:00:00 2001 From: justinsubert Date: Fri, 21 Jun 2013 10:26:43 +0100 Subject: [PATCH] HHH-8319 --- .../org/hibernate/dialect/MySQL5Dialect.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL5Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL5Dialect.java index 6065a7dada..fbef8ae0d5 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL5Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL5Dialect.java @@ -23,8 +23,13 @@ */ package org.hibernate.dialect; +import java.sql.SQLException; import java.sql.Types; +import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter; +import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; +import org.hibernate.internal.util.JdbcExceptionHelper; + /** * An SQL dialect for MySQL 5.x specific features. * @@ -43,4 +48,27 @@ public class MySQL5Dialect extends MySQLDialect { public boolean supportsColumnCheck() { return false; } + + public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() { + return EXTRACTER; + } + + private static ViolatedConstraintNameExtracter EXTRACTER = new TemplatedViolatedConstraintNameExtracter() { + + public String extractConstraintName(SQLException sqle) { + try { + int sqlState = Integer.valueOf( JdbcExceptionHelper.extractSqlState( sqle ) ).intValue(); + switch ( sqlState ) { + case 23000: + return extractUsingTemplate( " for key '", "'", sqle.getMessage() ); + default: + return null; + } + } + catch (NumberFormatException nfe) { + return null; + } + } + }; + }