Skip to content

Commit ce33afc

Browse files
Burkhard Gravesbeikov
authored andcommitted
HHH-15591: added two tests in UnidirectionalOneToManyOrderColumnTest
1 parent ee6fd38 commit ce33afc

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
@@ -180,6 +180,59 @@ public void testRemovingOneAndAddingTwoElements(EntityManagerFactoryScope scope)
180180
);
181181
}
182182

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

0 commit comments

Comments
 (0)