Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-15591 Unidirectional @OneToMany with @OrderColumn still throwing ConstraintViolationException (unique index violation) #5401

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,59 @@ public void testRemovingOneAndAddingTwoElements(EntityManagerFactoryScope scope)
);
}

@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<ChildData> 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<ChildData> 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 {
Expand Down
Loading