-->
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: Result contains duplicate classes
PostPosted: Wed Apr 02, 2008 10:34 am 
Newbie

Joined: Wed Apr 02, 2008 10:10 am
Posts: 5
I am using an HQL query via Spring template as below:

return (List)getHibernateTemplate().find("from Despatch d left join fetch d.despatchItems di" +
" where d.externalReceiptReference=? and d.id = di.despatch order by d.despatchCounter desc"
, new Object[] {externalReceiptReference});

The Despatch class contains a Set of DespatchItems and a DespatchItem contains a reference to it's parent (despatch Class).

The relevant part of the mapping file looks like this:

<hibernate-mapping package="com.bbb.domain">
<class name="Despatch" table="Despatch">

<id name="id" type="long" column="despatchid" unsaved-value="null">
<generator class="assigned"/>
</id>
<set name="despatchItems" inverse="true" order-by="line_number" cascade="none" fetch="join" lazy="false">
<key column="despatchid"/>
<one-to-many class="DespatchItem"/>
</set>..........................


I can understand in terms of SQL how this will return a result set with one row for each despatchItem.
With hibernate if I have one Despatch Object containing three DespatchItems,
The resulting List contains three identical Despatch classes, each containing and identical list of DespatchItems.

How to I "tell" hibernate to return only unique objects in this case?

Spring 2.5
hibernate 3.2
db2 v9.1

Many thanks in advance if you can point me in the correct direction.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 12:03 pm 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
when you copy the title of your post into the google seach field an hit return,
you will get to this site:

http://www.google.com/search?q=Result+c ... te+classes

click the currently second result:

http://opensource.atlassian.com/project ... e/HHH-1781

and here you are, at the solution to the problem.

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 12:10 pm 
Beginner
Beginner

Joined: Fri Aug 24, 2007 4:46 am
Posts: 36
Location: Bielefeld / Germany
Please try a "select distinct d from Despatch d ..."

And please read:

http://www.hibernate.org/117.html#A12


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 03, 2008 2:40 am 
Newbie

Joined: Wed Apr 02, 2008 10:10 am
Posts: 5
Thanks schauder,

As you can see from my code, I am not not using criteria queries.
This is because the way the job was originally coded: (No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here).

So I am just going to use collections in Java to filter the results for now.

But thanks for graceful spirit, by the way when you copy "grace: definition" into the google search field an hit return, you will get to this site:

http://www.google.co.uk/search?hl=en&q= ... gle+Search

Click on any of the top results and browse:


Top
 Profile  
 
 Post subject: RE: Result contains duplicate classes
PostPosted: Thu Apr 03, 2008 2:50 am 
Newbie

Joined: Wed Apr 02, 2008 10:10 am
Posts: 5
Thanks schauder,

As you can see from my code, I am not not using criteria queries.
This is because the way the job was originally coded: (No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here).

So I am just going to use collections in Java to filter the results for now.

But thanks for graceful spirit, by the way when you copy "grace: definition" into the google search field an hit return, you will get to this site:

http://www.google.co.uk/search?hl=en&q= ... gle+Search

Click on any of the top results and browse:


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.