From 7c7021b086ca07b2c4fa6bb741bc6c6268f8fc2e Mon Sep 17 00:00:00 2001 From: Burkhard Graves Date: Mon, 10 Oct 2022 20:20:55 +0200 Subject: [PATCH] HHH-15591: added two tests in UnidirectionalOneToManyOrderColumnTest --- ...nidirectionalOneToManyOrderColumnTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyOrderColumnTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyOrderColumnTest.java index 986c8f3969..82d92af44b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyOrderColumnTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyOrderColumnTest.java @@ -182,6 +182,59 @@ public class UnidirectionalOneToManyOrderColumnTest { ); } + @Test + public void testSwapElementsAtZeroAndOne(EntityManagerFactoryScope scope) { + long parentId = scope.fromTransaction( + entityManager -> { + ParentData parent = new ParentData(); + entityManager.persist( parent ); + + String[] childrenStr = new String[] {"One", "Two"}; + for ( String str : childrenStr ) { + ChildData child = new ChildData( str ); + entityManager.persist( child ); + parent.getChildren().add( child ); + } + + entityManager.flush(); + + List children = parent.getChildren(); + ChildData child0 = children.get( 0 ); + ChildData child1 = children.get( 1 ); + children.set(0, child1); + children.set(1, child0); + + return parent.id; + } + ); + // if the above works, then test on {"Two", "One"} + } + + @Test + public void testAddAtZeroDeleteAtTwo(EntityManagerFactoryScope scope) { + long parentId = scope.fromTransaction( + entityManager -> { + ParentData parent = new ParentData(); + entityManager.persist( parent ); + + String[] childrenStr = new String[] {"One", "Two"}; + for ( String str : childrenStr ) { + ChildData child = new ChildData( str ); + entityManager.persist( child ); + parent.getChildren().add( child ); + } + + entityManager.flush(); + + List children = parent.getChildren(); + children.add( 0, new ChildData( "Zero" ) ); + children.remove( 2 ); + return parent.id; + } + ); + // if the above works, then test on {"Zero", "One"} + } + @Entity(name = "ParentData") @Table(name = "PARENT") public static class ParentData {