File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
hibernate-core/src/main/java/org/hibernate/dialect Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 2222 * Boston, MA 02110-1301 USA
2323 */
2424package org .hibernate .dialect ;
25+
26+ import java .sql .SQLException ;
2527import java .sql .Types ;
2628
29+ import org .hibernate .exception .spi .TemplatedViolatedConstraintNameExtracter ;
30+ import org .hibernate .exception .spi .ViolatedConstraintNameExtracter ;
31+ import org .hibernate .internal .util .JdbcExceptionHelper ;
32+
2733/**
2834 * An SQL dialect for MySQL 5.x specific features.
2935 *
@@ -46,4 +52,27 @@ protected void registerVarcharTypes() {
4652 public boolean supportsColumnCheck () {
4753 return false ;
4854 }
55+
56+ public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter () {
57+ return EXTRACTER ;
58+ }
59+
60+ private static ViolatedConstraintNameExtracter EXTRACTER = new TemplatedViolatedConstraintNameExtracter () {
61+
62+ public String extractConstraintName (SQLException sqle ) {
63+ try {
64+ int sqlState = Integer .valueOf ( JdbcExceptionHelper .extractSqlState ( sqle ) ).intValue ();
65+ switch ( sqlState ) {
66+ case 23000 :
67+ return extractUsingTemplate ( " for key '" , "'" , sqle .getMessage () );
68+ default :
69+ return null ;
70+ }
71+ }
72+ catch (NumberFormatException nfe ) {
73+ return null ;
74+ }
75+ }
76+ };
77+
4978}
You can’t perform that action at this time.
0 commit comments