Hi list,
I have a question regarding eager fetching with the Criteria interfaces.
I have a parent/child relationship where some parents have zero children. Now, when I fetch the parent with HQL specifying
Code:
left join fetch
, everything works fine. However, the behaviour is a bit different with the Criteria interfaces: A parent that has no children, won't have its collection of children initalized.
Did I miss something in the docs? Thanks for your help,
Jan
Hibernate version: 2.1.6
Mapping documents:Code between sessionFactory.openSession() and session.close():Code:
// get parent without children
List l = session.find("from Parent p left join fetch p.children where p.id=1");
Parent p = (Parent) l.get(0);
assertTrue(Hibernate.isInitalized(p.getChildren()); // ok
// Same query with Criteria
List l = session.createCriteria(Parent.class).setFetchMode("children",
FetchMode.EAGER).add( Expression.eq("id", new Integer(1)).list();
Parent p = (Parent) l.get(0);
assertTrue(Hibernate.isInitalized(p.getChildren()); // fails if p has 0 children in db
Full stack trace of any exception that occurs:
Name and version of the database you are using: MySQL 4.0.18
Debug level Hibernate log excerpt: