Skip to content

Commit ed5f081

Browse files
author
Burkhard Graves
committed
HHH-15591: added two tests in UnidirectionalOneToManyOrderColumnTest
1 parent 4453af9 commit ed5f081

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
@@ -182,6 +182,59 @@ public void testRemovingOneAndAddingTwoElements(EntityManagerFactoryScope scope)
182182
);
183183
}
184184

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

0 commit comments

Comments
 (0)