-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Collection not initalized after eager fetch
PostPosted: Mon Sep 06, 2004 5:24 am 
Newbie

Joined: Mon Sep 06, 2004 5:00 am
Posts: 1
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:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.