HHH-11587 - Add test for issue
This commit is contained in:
parent
c488e8e081
commit
aaa6df26e1
|
@ -7,32 +7,37 @@
|
||||||
package org.hibernate.jpa.test.mapping;
|
package org.hibernate.jpa.test.mapping;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collector;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.OrderColumn;
|
import javax.persistence.OrderColumn;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
import org.hibernate.testing.FailureExpected;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
@TestForIssue(jiraKey = "HHH-11587")
|
||||||
public class UnidirectionalOneToManyOrderColumnTest extends BaseEntityManagerFunctionalTestCase {
|
public class UnidirectionalOneToManyOrderColumnTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpected( jiraKey = "HHH-11587" )
|
public void testRemovingAnElement() {
|
||||||
public void testQuote() {
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||||
|
|
||||||
ParentData parent = new ParentData();
|
ParentData parent = new ParentData();
|
||||||
entityManager.persist( parent );
|
entityManager.persist( parent );
|
||||||
|
|
||||||
String[] childrenStr = new String[] { "One", "Two", "Three", "Four", "Five" };
|
String[] childrenStr = new String[] {"One", "Two", "Three"};
|
||||||
for ( String str : childrenStr ) {
|
for ( String str : childrenStr ) {
|
||||||
ChildData child = new ChildData( str );
|
ChildData child = new ChildData( str );
|
||||||
entityManager.persist( child );
|
entityManager.persist( child );
|
||||||
|
@ -46,6 +51,57 @@ public class UnidirectionalOneToManyOrderColumnTest extends BaseEntityManagerFun
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddingAnElement() {
|
||||||
|
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||||
|
|
||||||
|
ParentData parent = new ParentData();
|
||||||
|
entityManager.persist( parent );
|
||||||
|
|
||||||
|
String[] childrenStr = new String[] {"One", "Two", "Three"};
|
||||||
|
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( 1, new ChildData( "Another" ) );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemovingAndAddingAnElement() {
|
||||||
|
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||||
|
|
||||||
|
ParentData parent = new ParentData();
|
||||||
|
entityManager.persist( parent );
|
||||||
|
|
||||||
|
String[] childrenStr = new String[] {"One", "Two", "Three"};
|
||||||
|
for ( String str : childrenStr ) {
|
||||||
|
ChildData child = new ChildData( str );
|
||||||
|
entityManager.persist( child );
|
||||||
|
parent.getChildren().add( child );
|
||||||
|
}
|
||||||
|
|
||||||
|
entityManager.flush();
|
||||||
|
|
||||||
|
List<ChildData> children = parent.getChildren();
|
||||||
|
children.remove( 0 );
|
||||||
|
children.add( 1, new ChildData( "Another" ) );
|
||||||
|
} );
|
||||||
|
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||||
|
|
||||||
|
ParentData parent = entityManager.find( ParentData.class, 1L );
|
||||||
|
List<String> childIds = parent.getChildren().stream().map( ChildData::toString ).collect( Collectors.toList() );
|
||||||
|
int i = 0;
|
||||||
|
assertEquals( "Two", childIds.get( i++ ));
|
||||||
|
assertEquals( "Another", childIds.get( i++ ));
|
||||||
|
assertEquals( "Three", childIds.get( i++ ));
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
|
@ -55,7 +111,8 @@ public class UnidirectionalOneToManyOrderColumnTest extends BaseEntityManagerFun
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity(name = "ParentData")
|
||||||
|
@Table(name = "PARENT")
|
||||||
public static class ParentData {
|
public static class ParentData {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -70,7 +127,8 @@ public class UnidirectionalOneToManyOrderColumnTest extends BaseEntityManagerFun
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity(name = "ChildData")
|
||||||
|
@Table(name = "CHILD")
|
||||||
public static class ChildData {
|
public static class ChildData {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
|
Loading…
Reference in New Issue