-->
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.  [ 5 posts ] 
Author Message
 Post subject: Join fetch not working the way I want it to
PostPosted: Tue Aug 29, 2006 10:08 am 
Newbie

Joined: Fri Jun 16, 2006 3:41 pm
Posts: 18
Hi, I have a simple one to many relation between MachineClass and MachineDataInstance tables. There are 6 entries in the MachineClass. I want to write a query that will get me a list of 6 MachineClass objects and initialize the Set member variable of all the related MachineDataInstance instances.

So I use the following query:
[code]
List list = session.createQuery("select distinct(mc) " +
"from MachineClass as mc " +
"left join fetch mc.MachineDataInstanceSet mdis").list();
[/code]

This however just gives me a list of a lot more than 6 objects that I expect. In fact for every related object in MachineDataInstance it duplicates the MachineClass in the list. So if I have only machine class "A" and 1999, 2000,2001 instances I get a list of size 3 (not what I want).

Why isn't this working for me? I want to get the data back in the way I put it into the database using a simple query.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 11:02 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://hibernate.org/117.html#A11


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 11:44 am 
Newbie

Joined: Fri Jun 16, 2006 3:41 pm
Posts: 18
Thanks for the help. I guess I misunderstood the documentation and this seems like a weird way of doing things.

What if I wanted to create a query with order by clause. Then the List is ordered but the hashset is not and I have to write a compareTo for every single class and sort the set of objects instead of letting the database do the sorting.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 11:54 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
man SortedSet


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 11:55 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
or LinkedHashSet...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.