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: Fetching a whole graph of objects using the Criteria API
PostPosted: Fri Sep 19, 2008 9:44 am 
Newbie

Joined: Thu Sep 18, 2008 11:14 am
Posts: 2
Location: Paris
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.


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.