Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1
I want to search an entity object that has other entity objects as children (In a one to many relationship). Below is an example of what I more of less have. Since the search will have multi-criteria, it made sense for me to use the qbe.
Code:
public class Parent implements Serializable
{
private Integer id;
private String name;
private List addresses;
private List children; (of type Child)
...
}
public class Child
{
private Integer id;
private String name;
...
}
For searching the method looks something like this.
public Collection search(Parent parent, Child child)
{
Example example = Example.create(parent)
.ignoreCase()
.excludeZeroes()
.excludeProperty("doNotUse")
.enableLike(MatchMode.ANYWHERE);
session = sessionFactory.openSession();
return session.createCriteria(c).add(example)
.createCriteria("children")
.add( Example.create( child) )
.list();
... sessionFactory.session.close();
}
Error: hibernate error:org.hibernate.QueryException: could not resolve property: children of: com....Parent
Question: The error makes sense, but how can I add criteria to the query so that for example I'm able to list all parents that have a child with the name x, and so on for all of the other parent properties.
I read the documentation but I'm still confused as to how to reference the children.
Please advice.