Hi,
I have the need to fetch a whole graph of objects using the Criteria API.
Let's take the following example : companies have departments, each department having a manager.
From what I've understood, my need might be fullfilled by the following lines of code :
Code:
List result = sess.createCriteria(Company.class)
.add( Restrictions.like("name", "%Inc") )
.setFetchMode("departments", FetchMode.EAGER)
.createCriteria("departments")
.setFetchMode("manager", FetchMode.EAGER)
.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
.list();
Iterator iter = result.iterator();
Map map = null;
Company company = null;
while ( iter.hasNext() ) {
map = (Map) iter.next();
company = (Company) map.get(Criteria.ROOT_ALIAS);
...
}
Is this correct ? If not, how can I do ?
Thanks in advance.
Regards.
Patrice.