1414import jakarta .persistence .Table ;
1515import jakarta .persistence .UniqueConstraint ;
1616import org .hibernate .community .dialect .InformixDialect ;
17+ import org .hibernate .dialect .CockroachDialect ;
1718import org .hibernate .dialect .DB2Dialect ;
1819import org .hibernate .dialect .HANADialect ;
1920import org .hibernate .exception .ConstraintViolationException ;
2021import org .hibernate .testing .orm .junit .EntityManagerFactoryScope ;
2122import org .hibernate .testing .orm .junit .Jpa ;
22- import org .hibernate .testing .orm .junit .SkipForDialect ;
2323import org .junit .jupiter .api .Test ;
2424
2525import static org .junit .jupiter .api .Assertions .assertEquals ;
@@ -37,6 +37,7 @@ public class ConstraintInterpretationTest2 {
3737 }
3838 catch (ConstraintViolationException cve ) {
3939 assertEquals ( ConstraintViolationException .ConstraintKind .NOT_NULL , cve .getKind () );
40+ // DB2 and Informix error messages don't contain the primary key constraint name
4041 if ( !(scope .getDialect () instanceof DB2Dialect ) && !(scope .getDialect () instanceof InformixDialect ) ) {
4142 assertTrue ( cve .getConstraintName ().toLowerCase ().endsWith ( "id" ) );
4243 }
@@ -63,6 +64,7 @@ public class ConstraintInterpretationTest2 {
6364 }
6465 catch (ConstraintViolationException cve ) {
6566 assertEquals ( ConstraintViolationException .ConstraintKind .NOT_NULL , cve .getKind () );
67+ // DB2 error message doesn't contain constraint or column name
6668 if ( !(scope .getDialect () instanceof DB2Dialect ) ) {
6769 assertTrue ( cve .getConstraintName ().toLowerCase ().endsWith ( "name" ) );
6870 }
@@ -78,15 +80,14 @@ public class ConstraintInterpretationTest2 {
7880 }
7981 catch (ConstraintViolationException cve ) {
8082 assertEquals ( ConstraintViolationException .ConstraintKind .UNIQUE , cve .getKind () );
83+ // DB2 error message doesn't contain unique constraint name
8184 if ( !(scope .getDialect () instanceof DB2Dialect ) ) {
8285 assertTrue ( cve .getConstraintName ().toLowerCase ().contains ( "ssnuk" ) );
8386 }
8487 }
8588 } );
8689 }
8790
88- @ SkipForDialect (dialectClass = InformixDialect .class ,
89- reason = "multi-column check constraints must be created using 'alter table', and we don't have a StandardCheckConstraintExporter" )
9091 @ Test void testCheck (EntityManagerFactoryScope scope ) {
9192 scope .inTransaction ( em -> {
9293 try {
@@ -95,7 +96,10 @@ public class ConstraintInterpretationTest2 {
9596 }
9697 catch (ConstraintViolationException cve ) {
9798 assertEquals ( ConstraintViolationException .ConstraintKind .CHECK , cve .getKind () );
98- assertTrue ( cve .getConstraintName ().toLowerCase ().endsWith ( "namecheck" ) );
99+ // CockroachDB error messages don't contain the check constraint name
100+ if ( !(scope .getDialect () instanceof CockroachDialect ) ) {
101+ assertTrue ( cve .getConstraintName ().toLowerCase ().endsWith ( "namecheck" ) );
102+ }
99103 }
100104 } );
101105 }
@@ -107,6 +111,7 @@ public class ConstraintInterpretationTest2 {
107111 }
108112 catch (ConstraintViolationException cve ) {
109113 assertEquals ( ConstraintViolationException .ConstraintKind .FOREIGN_KEY , cve .getKind () );
114+ // HANA error messages don't contain the foreign key constraint name
110115 if ( !(scope .getDialect () instanceof HANADialect ) ) {
111116 assertTrue ( cve .getConstraintName ().toLowerCase ().endsWith ( "id2to1fk" ) );
112117 }
0 commit comments