HHH-16120 Add test for issue
This commit is contained in:
parent
bea5bfbe89
commit
3f814d8845
|
@ -0,0 +1,46 @@
|
|||
package org.hibernate.orm.test.collection.list;
|
||||
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
public class Child {
|
||||
private Integer id;
|
||||
private String name;
|
||||
|
||||
|
||||
private Parent parent;
|
||||
|
||||
public Child() {
|
||||
}
|
||||
|
||||
public Child(Integer id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Id
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
public Parent getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(Parent parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package org.hibernate.orm.test.collection.list;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/orm/test/collection/list/ParentChildMapping.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class IterateOverListInTheSetMethodTest {
|
||||
|
||||
@BeforeAll
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Child child = new Child( 1, "Luigi" );
|
||||
Child child2 = new Child( 2, "Franco" );
|
||||
Parent parent = new Parent( 2, "Fabio" );
|
||||
parent.addChild( child );
|
||||
parent.addChild( child2 );
|
||||
|
||||
session.persist( parent );
|
||||
session.persist( child );
|
||||
session.persist( child2 );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHqlQuery(SessionFactoryScope scope) {
|
||||
scope.inSession(
|
||||
session -> {
|
||||
session.createQuery( "select p from Parent p" ).list();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package org.hibernate.orm.test.collection.list;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
|
||||
public class Parent {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
|
||||
|
||||
private List<Child> children = new ArrayList<>();
|
||||
|
||||
public Parent() {
|
||||
}
|
||||
|
||||
public Parent(Integer id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Id
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Child> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<Child> children) {
|
||||
this.children = children;
|
||||
for ( Iterator<Child> i = children.iterator(); i.hasNext(); ) {
|
||||
if ( i.next() == null ) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addChild(Child child) {
|
||||
this.children.add( child );
|
||||
child.setParent( this );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping default-lazy="false" package="org.hibernate.orm.test.collection.list">
|
||||
<class name="Parent" table="custom_field">
|
||||
<id name="id"/>
|
||||
<property name="name" column="name"/>
|
||||
<list name="children" inverse="true" cascade="all-delete-orphan">
|
||||
<key column="custom_field_id"/>
|
||||
<index column="seq_num"/>
|
||||
<one-to-many class="Child"/>
|
||||
</list>
|
||||
</class>
|
||||
<class name="Child" table="custom_field_option">
|
||||
<id name="id"/>
|
||||
<many-to-one name="parent" not-null="true" column="custom_field_id"/>
|
||||
</class>
|
||||
</hibernate-mapping>
|
Loading…
Reference in New Issue