88
99import java .util .Iterator ;
1010
11+ import javax .persistence .PersistenceException ;
12+
1113import org .junit .Test ;
1214
1315import org .hibernate .JDBCException ;
1921import org .hibernate .engine .spi .SessionImplementor ;
2022import org .hibernate .testing .junit4 .BaseCoreFunctionalTestCase ;
2123
24+ import static org .hibernate .testing .junit4 .ExtraAssertions .assertTyping ;
2225import static org .junit .Assert .assertEquals ;
2326import static org .junit .Assert .assertNotNull ;
2427import static org .junit .Assert .assertSame ;
4952 */
5053public class MultiPathCircleCascadeTest extends BaseCoreFunctionalTestCase {
5154 private static interface EntityOperation {
55+ boolean isLegacy ();
5256 Object doEntityOperation (Object entity , Session s );
5357 }
5458 private static EntityOperation MERGE_OPERATION =
5559 new EntityOperation () {
60+ @ Override
61+ public boolean isLegacy () {
62+ return false ;
63+ }
5664 @ Override
5765 public Object doEntityOperation (Object entity , Session s ) {
5866 return s .merge ( entity );
5967 }
6068 };
6169 private static EntityOperation SAVE_OPERATION =
6270 new EntityOperation () {
71+ @ Override
72+ public boolean isLegacy () {
73+ return true ;
74+ }
6375 @ Override
6476 public Object doEntityOperation (Object entity , Session s ) {
6577 s .save ( entity );
@@ -68,6 +80,10 @@ public Object doEntityOperation(Object entity, Session s) {
6880 };
6981 private static EntityOperation SAVE_UPDATE_OPERATION =
7082 new EntityOperation () {
83+ @ Override
84+ public boolean isLegacy () {
85+ return true ;
86+ }
7187 @ Override
7288 public Object doEntityOperation (Object entity , Session s ) {
7389 s .saveOrUpdate ( entity );
@@ -124,7 +140,8 @@ private void testEntityWithNonNullableTransientEntity(EntityOperation operation)
124140 checkExceptionFromNullValueForNonNullable (
125141 ex ,
126142 ((SessionImplementor ) s ).getFactory ().getSettings ().isCheckNullability (),
127- false
143+ false ,
144+ operation .isLegacy ()
128145 );
129146 }
130147 finally {
@@ -165,7 +182,8 @@ private void testEntityWithNonNullableEntityNull(EntityOperation operation) {
165182 checkExceptionFromNullValueForNonNullable (
166183 ex ,
167184 ((SessionImplementor ) s ).getFactory ().getSettings ().isCheckNullability (),
168- true
185+ true ,
186+ operation .isLegacy ()
169187 );
170188 }
171189 finally {
@@ -204,7 +222,8 @@ private void testEntityWithNonNullablePropSetToNull(EntityOperation operation) {
204222 checkExceptionFromNullValueForNonNullable (
205223 ex ,
206224 ((SessionImplementor ) s ).getFactory ().getSettings ().isCheckNullability (),
207- true
225+ true ,
226+ operation .isLegacy ()
208227 );
209228 }
210229 finally {
@@ -660,18 +679,28 @@ private void testData3Nodes(EntityOperation operation) {
660679 }
661680
662681 protected void checkExceptionFromNullValueForNonNullable (
663- Exception ex , boolean checkNullability , boolean isNullValue
682+ Exception ex , boolean checkNullability , boolean isNullValue , boolean isLegacy
664683 ) {
665684 if ( isNullValue ) {
666685 if ( checkNullability ) {
667- assertTrue ( ex instanceof PropertyValueException );
686+ if ( isLegacy ) {
687+ assertTyping ( PropertyValueException .class , ex );
688+ }
689+ else {
690+ assertTyping ( PersistenceException .class , ex );
691+ }
668692 }
669693 else {
670694 assertTrue ( (ex instanceof JDBCException ) || (ex .getCause () instanceof JDBCException ) );
671695 }
672696 }
673697 else {
674- assertTrue ( ex instanceof TransientPropertyValueException );
698+ if ( isLegacy ) {
699+ assertTyping ( TransientPropertyValueException .class , ex );
700+ }
701+ else {
702+ assertTyping ( IllegalStateException .class , ex );
703+ }
675704 }
676705 }
677706
0 commit comments