Skip to content

Commit eda339c

Browse files
committed
treat MySQL/Maria error code 1364 as NOT_NULL constraint violation
The message is "Field 'column' doesn't have a default value" but it happens when leaving a 'not null' column off a list of fields to insert, so it's essentially a violation of the not null constraint.
1 parent 9201e71 commit eda339c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ public ViolatedConstraintNameExtractor getViolatedConstraintNameExtractor() {
351351
case 1451, 1452, 4025 -> extractUsingTemplate( " CONSTRAINT `", "`", sqle.getMessage() );
352352
case 3819 -> extractUsingTemplate( " constraint '", "'", sqle.getMessage() );
353353
case 1048 -> extractUsingTemplate( "Column '", "'", sqle.getMessage() );
354+
case 1364 -> extractUsingTemplate( "Field '", "'", sqle.getMessage() );
354355
default -> null;
355356
} );
356357

@@ -375,7 +376,7 @@ public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
375376
// Unique constraint violation
376377
return new ConstraintViolationException( message, sqlException, sql, ConstraintKind.UNIQUE,
377378
getViolatedConstraintNameExtractor().extractConstraintName( sqlException ) );
378-
case 1048:
379+
case 1048, 1364:
379380
// Null constraint violation
380381
return new ConstraintViolationException( message, sqlException, sql, ConstraintKind.NOT_NULL,
381382
getViolatedConstraintNameExtractor().extractConstraintName( sqlException ) );

hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ public ViolatedConstraintNameExtractor getViolatedConstraintNameExtractor() {
983983
case 1451, 1452 -> extractUsingTemplate( " CONSTRAINT `", "`", sqle.getMessage() );
984984
case 3819-> extractUsingTemplate( " constraint '", "'", sqle.getMessage() );
985985
case 1048 -> extractUsingTemplate( "Column '", "'", sqle.getMessage() );
986+
case 1364 -> extractUsingTemplate( "Field '", "'", sqle.getMessage() );
986987
default -> null;
987988
} );
988989

@@ -1273,7 +1274,7 @@ public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
12731274
// Unique constraint violation
12741275
return new ConstraintViolationException( message, sqlException, sql, ConstraintKind.UNIQUE,
12751276
getViolatedConstraintNameExtractor().extractConstraintName( sqlException ) );
1276-
case 1048:
1277+
case 1048, 1364:
12771278
// Null constraint violation
12781279
return new ConstraintViolationException( message, sqlException, sql, ConstraintKind.NOT_NULL,
12791280
getViolatedConstraintNameExtractor().extractConstraintName( sqlException ) );

0 commit comments

Comments
 (0)