Skip to content

Commit 0035edc

Browse files
committed
Merge pull request #8 from Naros/steve_HHH-10664_2
Fix more test failures.
2 parents d600868 + 81410e2 commit 0035edc

File tree

7 files changed

+152
-108
lines changed

7 files changed

+152
-108
lines changed

hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ private Object fireMerge(MergeEvent event) {
855855
for ( MergeEventListener listener : listeners( EventType.MERGE ) ) {
856856
listener.onMerge( event );
857857
}
858+
checkNoUnresolvedActionsAfterOperation();
858859
}
859860
catch ( ObjectDeletedException sse ) {
860861
throw convert( new IllegalArgumentException( sse ) );
@@ -866,9 +867,6 @@ private Object fireMerge(MergeEvent event) {
866867
//including HibernateException
867868
throw convert( e );
868869
}
869-
finally {
870-
checkNoUnresolvedActionsAfterOperation();
871-
}
872870

873871
return event.getResult();
874872
}

hibernate-core/src/test/java/org/hibernate/test/cascade/MultiPathCascadeTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ public void testMultiPathMergeNonCascadedTransientEntityInCollection() throws Ex
176176
s.merge( a );
177177
s.merge( h );
178178
s.getTransaction().commit();
179-
fail( "should have thrown TransientObjectException" );
179+
fail( "should have thrown IllegalStateException" );
180180
}
181-
catch (TransientObjectException expected) {
181+
catch (IllegalStateException expected) {
182182
// expected
183183
}
184184
finally {
@@ -225,9 +225,9 @@ public void testMultiPathMergeNonCascadedTransientEntityInOneToOne() throws Exce
225225
s.merge( a );
226226
s.merge( g );
227227
s.getTransaction().commit();
228-
fail( "should have thrown TransientObjectException" );
228+
fail( "should have thrown IllegalStateException" );
229229
}
230-
catch (TransientObjectException expected) {
230+
catch (IllegalStateException expected) {
231231
// expected
232232
}
233233
finally {
@@ -274,9 +274,9 @@ public void testMultiPathMergeNonCascadedTransientEntityInManyToOne() throws Exc
274274
s.merge( a );
275275
s.merge( h );
276276
s.getTransaction().commit();
277-
fail( "should have thrown TransientObjectException" );
277+
fail( "should have thrown IllegalStateException" );
278278
}
279-
catch (TransientObjectException expected) {
279+
catch (IllegalStateException expected) {
280280
// expected
281281
}
282282
finally {

hibernate-core/src/test/java/org/hibernate/test/cascade/circle/MultiPathCircleCascadeTest.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import java.util.Iterator;
1010

11+
import javax.persistence.PersistenceException;
12+
1113
import org.junit.Test;
1214

1315
import org.hibernate.JDBCException;
@@ -19,6 +21,7 @@
1921
import org.hibernate.engine.spi.SessionImplementor;
2022
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
2123

24+
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
2225
import static org.junit.Assert.assertEquals;
2326
import static org.junit.Assert.assertNotNull;
2427
import static org.junit.Assert.assertSame;
@@ -49,17 +52,26 @@
4952
*/
5053
public 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

hibernate-core/src/test/java/org/hibernate/test/connections/ConnectionManagementTestCase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public final void testManualDisconnectChain() throws Throwable {
234234
public final void testManualDisconnectWithOpenResources() throws Throwable {
235235
prepare();
236236
Session sessionUnderTest = getSessionUnderTest();
237+
sessionUnderTest.beginTransaction();
237238

238239
Silly silly = new Silly( "tester" );
239240
sessionUnderTest.save( silly );
@@ -256,6 +257,8 @@ public final void testManualDisconnectWithOpenResources() throws Throwable {
256257
sessionUnderTest.delete( silly );
257258
sessionUnderTest.flush();
258259

260+
sessionUnderTest.getTransaction().commit();
261+
259262
release( sessionUnderTest );
260263
done();
261264
}

0 commit comments

Comments
 (0)