Skip to content

Commit 39a1ca2

Browse files
Burkhard Gravesdreab8
authored andcommitted
HHH-15591: added two tests in UnidirectionalOneToManyOrderColumnTest
1 parent d9b2011 commit 39a1ca2

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyOrderColumnTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,59 @@ public void testRemovingOneAndAddingTwoElements(EntityManagerFactoryScope scope)
176176
);
177177
}
178178

179+
@Test
180+
public void testSwapElementsAtZeroAndOne(EntityManagerFactoryScope scope) {
181+
long parentId = scope.fromTransaction(
182+
entityManager -> {
183+
ParentData parent = new ParentData();
184+
entityManager.persist( parent );
185+
186+
String[] childrenStr = new String[] {"One", "Two"};
187+
for ( String str : childrenStr ) {
188+
ChildData child = new ChildData( str );
189+
entityManager.persist( child );
190+
parent.getChildren().add( child );
191+
}
192+
193+
entityManager.flush();
194+
195+
List<ChildData> children = parent.getChildren();
196+
ChildData child0 = children.get( 0 );
197+
ChildData child1 = children.get( 1 );
198+
children.set(0, child1);
199+
children.set(1, child0);
200+
201+
return parent.id;
202+
}
203+
);
204+
// if the above works, then test on {"Two", "One"}
205+
}
206+
207+
@Test
208+
public void testAddAtZeroDeleteAtTwo(EntityManagerFactoryScope scope) {
209+
long parentId = scope.fromTransaction(
210+
entityManager -> {
211+
ParentData parent = new ParentData();
212+
entityManager.persist( parent );
213+
214+
String[] childrenStr = new String[] {"One", "Two"};
215+
for ( String str : childrenStr ) {
216+
ChildData child = new ChildData( str );
217+
entityManager.persist( child );
218+
parent.getChildren().add( child );
219+
}
220+
221+
entityManager.flush();
222+
223+
List<ChildData> children = parent.getChildren();
224+
children.add( 0, new ChildData( "Zero" ) );
225+
children.remove( 2 );
226+
return parent.id;
227+
}
228+
);
229+
// if the above works, then test on {"Zero", "One"}
230+
}
231+
179232
@Entity(name = "ParentData")
180233
@Table(name = "PARENT")
181234
public static class ParentData {

0 commit comments

Comments
 (0)