[JIRA] (HHH-15591) Unidirectional @OneToMany with @OrderColumn still throwing ConstraintViolationException (unique index violation)
by Burkhard Graves (JIRA)
Burkhard Graves ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZTk2YWZlZDcx... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-15591?atlOrigin=eyJpIjoiZTk2YW... ) HHH-15591 ( https://hibernate.atlassian.net/browse/HHH-15591?atlOrigin=eyJpIjoiZTk2YW... ) Unidirectional @OneToMany with @OrderColumn still throwing ConstraintViolationException (unique index violation) ( https://hibernate.atlassian.net/browse/HHH-15591?atlOrigin=eyJpIjoiZTk2YW... )
Change By: Burkhard Graves ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
There are several tickets dealing with this setup, see linked issues.
What seems to work:
* Adding one or more elements to the list
* Removing one or more elements from the list
What still does not work:
* Swapping elements in the list
* Simultaneously adding and removing elements from the list
I added created a PR which adds two tests to {{UnidirectionalOneToManyOrderColumnTest}}, namely
{code:java} @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"}
}{code}
Both tests fail (in h2 and presumably many other databases).
( https://hibernate.atlassian.net/browse/HHH-15591#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15591#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100207- sha1:591c2ef )
2 years, 3 months
[JIRA] (HHH-15591) Unidirectional @OneToMany with @OrderColumn still throwing ConstraintViolationException (unique index violation)
by Burkhard Graves (JIRA)
Burkhard Graves ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNzNhOTExMmIx... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-15591?atlOrigin=eyJpIjoiNzNhOT... ) HHH-15591 ( https://hibernate.atlassian.net/browse/HHH-15591?atlOrigin=eyJpIjoiNzNhOT... ) Unidirectional @OneToMany with @OrderColumn still throwing ConstraintViolationException (unique index violation) ( https://hibernate.atlassian.net/browse/HHH-15591?atlOrigin=eyJpIjoiNzNhOT... )
Change By: Burkhard Graves ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
There are several tickets dealing with this setup, see linked issues.
What seems to work:
* Adding one or more elements to the list
* Removing one or more elements from the list
What still does not work:
* Swapping elements in the list
* Simultaneously adding and removing elements from the list
I added a PR which adds to two tests to {{UnidirectionalOneToManyOrderColumnTest}}, namely
{code:java} @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"}
}{code}
Both tests fail (in h2 and presumably many other databases).
( https://hibernate.atlassian.net/browse/HHH-15591#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15591#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100207- sha1:591c2ef )
2 years, 3 months
[JIRA] (HHH-15591) Unidirectional @OneToMany with @OrderColumn still throwing ConstraintViolationException (unique index violation)
by Burkhard Graves (JIRA)
Burkhard Graves ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNjU4Nzk0MTEy... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-15591?atlOrigin=eyJpIjoiNjU4Nz... ) HHH-15591 ( https://hibernate.atlassian.net/browse/HHH-15591?atlOrigin=eyJpIjoiNjU4Nz... ) Unidirectional @OneToMany with @OrderColumn still throwing ConstraintViolationException (unique index violation) ( https://hibernate.atlassian.net/browse/HHH-15591?atlOrigin=eyJpIjoiNjU4Nz... )
Change By: Burkhard Graves ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
There are several tickets dealing with this setup, see linked issues.
What seems to work:
* Adding one or more elements to the list
* Removing one or more elements from the list
What still does not work:
* Swapping elements in the list
* Simultaneously adding and removing elements from the list
I added a PR which adds to tests to {{UnidirectionalOneToManyOrderColumnTest}}, namely
{code:java} @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"}
}{code}
Both tests fail (in h2 and presumably many other databases).
( https://hibernate.atlassian.net/browse/HHH-15591#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15591#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100207- sha1:591c2ef )
2 years, 3 months