-->
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: list() with left outer join query
PostPosted: Mon Aug 01, 2005 2:45 pm 
Newbie

Joined: Mon Aug 01, 2005 2:30 pm
Posts: 1
Hi, I'm using Hibernate 3.0.

This question may be a bit elementary but I have the following query, in which instances of a product (referred to as a 'type') are fetched along with keywords describing it :

Code:
select i from Instance as i  left outer join fetch  i.keywords as keywords join fetch i.type where i.status <> :status and i.user.id =:uid


My expectation was to get a list of POJOs made up of com.acme.Instance and have the keywords fall under getKeywords().

Perhaps I've misunderstood something gravely, but if I enter a single instance with 3 keywords, calling list() upon the query above (after all parameters have been set) returns a list of 3 Instance POJOs (each with the appropriate keywords) rather than a single Instance POJO with a list of 3 keywords in the getKeywords() property. Is there any way to get Hibernate to return a single object instead?


Top
 Profile  
 
 Post subject: Re: list() with left outer join query
PostPosted: Mon Aug 01, 2005 3:11 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
aclboston wrote:
Hi, I'm using Hibernate 3.0.

This question may be a bit elementary but I have the following query, in which instances of a product (referred to as a 'type') are fetched along with keywords describing it :

Code:
select i from Instance as i  left outer join fetch  i.keywords as keywords join fetch i.type where i.status <> :status and i.user.id =:uid


My expectation was to get a list of POJOs made up of com.acme.Instance and have the keywords fall under getKeywords().

Perhaps I've misunderstood something gravely, but if I enter a single instance with 3 keywords, calling list() upon the query above (after all parameters have been set) returns a list of 3 Instance POJOs (each with the appropriate keywords) rather than a single Instance POJO with a list of 3 keywords in the getKeywords() property. Is there any way to get Hibernate to return a single object instead?


The multiple results is the result of the outer-join. If you add your results to a Set, it'll remove duplicates and leave you with what you want.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


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.