-->
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.  [ 2 posts ] 
Author Message
 Post subject: FetchMode.Join
PostPosted: Fri Apr 10, 2009 12:45 pm 
Newbie

Joined: Mon Apr 06, 2009 4:32 pm
Posts: 4
Hi,

I've a table A with a oneToMany mapping on table B.

I use the following criteria to do a eager fetch

Code:

List<A> aList  =currentSession().createCriteria(A.class).
                         add(Restrictions.eq("user.id", userId)).
                         setFetchMode("b", FetchMode.JOIN).
                         list();



Query wise, it does what I expected it to do, ie., used outer join to get all "A" and the "B"s corresponding to each "A"

However, I expected the object to me mapped properly. ie., if there are two matching rows in "A" and each one has two matching rows in "B" then
I expected the returned list to be of size 2 with each one having a set "B" of size 2.

However, I am actually getting a size 4 which is what the query directly returns.

Should I be doing an explicit mapping to convert the query results to domain objects. I am getting lost here


Top
 Profile  
 
 Post subject: Got it
PostPosted: Fri Apr 10, 2009 2:27 pm 
Newbie

Joined: Mon Apr 06, 2009 4:32 pm
Posts: 4
setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY). helps!!


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

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.