I have a Parent class and a Child class with the current setup
Code:
@Entity
public class Parent {
@OneToMany(mappedBy = "parent")
private Set<Child> children;
@Column
private int type;
}
@Entity
public class Child {
@ManyToOne
@JoinColumn(name = "parent_id")
private Parent parent;
}
For some functions, I want to when querying the parent based on its type, the child is automatically retrieved and filled into the set.
This is what I have tried so far
Code:
res = getSession().createCriteria(
Parent.class, "parent"
).createAlias(
"parent.children", "children"
).add(
Restrictions.eq("parent.type", type)
).setFetchMode(
"children", FetchMode.JOIN
).list();
When I run the unit test, the getter is always equals to Null
Code:
assertEquals(1, res.get(0).getChildren());
How can I fix this ?