-->
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.  [ 6 posts ] 
Author Message
 Post subject: Named Queries: Duplicated Objects in Fetch Joins
PostPosted: Sat Oct 15, 2005 8:58 am 
Regular
Regular

Joined: Tue May 24, 2005 9:06 am
Posts: 64
Hibernate: 3.1rc1
Hibernate annotations: 3.1beta6
Database: PostgreSQL 8.1beta3

I'm using a fetch join for a one-to-many relationship with lazy loading, e.g. one customer has several orders. When I submit a named query to retrieve customers and load their orders orders, too, then each customer object will be duplicated. For instance, if customer with id=1 has 3 orders then I'll get 3 customer objects each having id=1.

The named query is defined as follows:
SELECT DISTINCT c
FROM CustomerData c LEFT JOIN FETCH c.orders
WHERE c.name = :name

I understand the semantics of a left outer join. However, I'd expect that the "SELECT DISTINCT" option would eliminate duplicates from the result set.

Any hint is appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 8:26 am 
Newbie

Joined: Fri Oct 14, 2005 1:27 am
Posts: 14
Location: Bangalore
when you say DISTINCT c, the records which are returned will be distinct with respect to all the collumns on the table Customerdata, it wont be on a single collumn.

you should specify the collumn name else all the collumns will be considered.

Abhi
Rate it if solves your problem


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 1:20 am 
Regular
Regular

Joined: Tue May 24, 2005 9:06 am
Posts: 64
Specifying a column name returns duplicate values, too. I'll submit a bug report.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 5:58 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
juergen.zimmermann wrote:
Specifying a column name returns duplicate values, too. I'll submit a bug report.

Don't,
To distinct you objects when fetch is used, use a HashSet
Code:
new HashSet( result );

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 7:54 am 
Newbie

Joined: Fri Oct 14, 2005 8:56 am
Posts: 6
so, if i want to keep the right order of list, i should use LinkedHashSet insteed, am i right?

i have the same duplicate problem, is it a bug or a feature?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 8:08 am 
Regular
Regular

Joined: Tue May 24, 2005 9:06 am
Posts: 64
Having the duplicates is a feature (see FAQ). Using LinkedHashSet is a reasonable solution to preserve the ordering.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.