|
49 | 49 | import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
|
50 | 50 | import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
|
51 | 51 | import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
|
52 |
| -import org.hibernate.internal.util.JdbcExceptionHelper; |
53 | 52 | import org.hibernate.mapping.AggregateColumn;
|
54 | 53 | import org.hibernate.mapping.Table;
|
55 | 54 | import org.hibernate.metamodel.mapping.EntityMappingType;
|
|
105 | 104 | import jakarta.persistence.GenerationType;
|
106 | 105 | import jakarta.persistence.TemporalType;
|
107 | 106 |
|
| 107 | +import static java.lang.Integer.parseInt; |
108 | 108 | import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
|
| 109 | +import static org.hibernate.internal.util.JdbcExceptionHelper.extractSqlState; |
109 | 110 | import static org.hibernate.query.common.TemporalUnit.DAY;
|
110 | 111 | import static org.hibernate.query.common.TemporalUnit.EPOCH;
|
111 | 112 | import static org.hibernate.type.SqlTypes.ARRAY;
|
@@ -1019,37 +1020,25 @@ public ViolatedConstraintNameExtractor getViolatedConstraintNameExtractor() {
|
1019 | 1020 | */
|
1020 | 1021 | private static final ViolatedConstraintNameExtractor EXTRACTOR =
|
1021 | 1022 | new TemplatedViolatedConstraintNameExtractor( sqle -> {
|
1022 |
| - final String sqlState = JdbcExceptionHelper.extractSqlState( sqle ); |
| 1023 | + final String sqlState = extractSqlState( sqle ); |
1023 | 1024 | if ( sqlState != null ) {
|
1024 |
| - switch ( Integer.parseInt( sqlState ) ) { |
1025 |
| - // CHECK VIOLATION |
1026 |
| - case 23514: |
1027 |
| - return extractUsingTemplate( "violates check constraint \"", "\"", sqle.getMessage() ); |
1028 |
| - // UNIQUE VIOLATION |
1029 |
| - case 23505: |
1030 |
| - return extractUsingTemplate( "violates unique constraint \"", "\"", sqle.getMessage() ); |
1031 |
| - // FOREIGN KEY VIOLATION |
1032 |
| - case 23503: |
1033 |
| - return extractUsingTemplate( "violates foreign key constraint \"", "\"", sqle.getMessage() ); |
1034 |
| - // NOT NULL VIOLATION |
1035 |
| - case 23502: |
1036 |
| - return extractUsingTemplate( |
1037 |
| - "null value in column \"", |
1038 |
| - "\" violates not-null constraint", |
1039 |
| - sqle.getMessage() |
1040 |
| - ); |
1041 |
| - // TODO: RESTRICT VIOLATION |
1042 |
| - case 23001: |
1043 |
| - return null; |
1044 |
| - } |
| 1025 | + return switch ( parseInt( sqlState ) ) { |
| 1026 | + case 23505, 23514, 23503 -> |
| 1027 | + // UNIQUE, CHECK, OR FOREIGN KEY VIOLATION |
| 1028 | + extractUsingTemplate( "constraint \"", "\"", sqle.getMessage() ); |
| 1029 | + case 23502 -> |
| 1030 | + // NOT NULL VIOLATION |
| 1031 | + extractUsingTemplate( "column \"", "\"", sqle.getMessage() ); |
| 1032 | + default -> null; |
| 1033 | + }; |
1045 | 1034 | }
|
1046 | 1035 | return null;
|
1047 | 1036 | } );
|
1048 | 1037 |
|
1049 | 1038 | @Override
|
1050 | 1039 | public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
|
1051 | 1040 | return (sqlException, message, sql) -> {
|
1052 |
| - final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException ); |
| 1041 | + final String sqlState = extractSqlState( sqlException ); |
1053 | 1042 | if ( sqlState != null ) {
|
1054 | 1043 | switch ( sqlState ) {
|
1055 | 1044 | case "40P01":
|
|
0 commit comments