-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
hibernate-core/src/test/java/org/hibernate/orm/test/collection/list/Child.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...c/test/java/org/hibernate/orm/test/collection/list/IterateOverListInTheSetMethodTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
hibernate-core/src/test/java/org/hibernate/orm/test/collection/list/Parent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...nate-core/src/test/java/org/hibernate/orm/test/collection/list/ParentChildMapping.hbm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |