-->
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.  [ 3 posts ] 
Author Message
 Post subject: Quick question about fetching and sorting
PostPosted: Thu Jan 27, 2005 12:03 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
I know I used to remember the answer to this question, but my memory is really bad. When I left join fetch to a collection, I have to filter out the duplicates in the parent collection, correct? I think I used to use a HashSet for this. If that's the case, then it's necessary to resort the collection? Or is there another way around this approach? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 12:49 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
It seems I have to take out the order by and do a sort in Java. From the code belowl the results are not sorted anymore (as I expected). Is sorting in Java the recommended approach or is there a better way?

Code:
               Query query = session.createQuery(
                  "select shipment " +
                  "from Shipment shipment " +
                  "   inner join shipment.cargoControlNumber.carrierCode.carrier.persons person " +
                  "   inner join shipment.currentStatus currentStatus " +
                  "   inner join currentStatus.releaseCode releaseCode " +
                  "   left join fetch shipment.currentStatus " +
                  "   left join fetch shipment.statusMessages " +
                  "where " +
                  "   person.id = :personId and " +
                  "   shipment.isPurged = false and " +
                  "   releaseCode.number = :releaseCodeNumber and " +
                  "   currentStatus is not null and " +
                  "   currentStatus.date >= current_date - 7 " +
                  "order by currentStatus.date desc"
               );

               query.setParameter( "personId", personId );
               query.setParameter( "releaseCodeNumber", releaseCodeNumber );

               query.setFirstResult( firstResult );
               query.setMaxResults( maxResults );

               List list = query.list();
               Set distinctShipments = new HashSet( list );
               return Arrays.asList( distinctShipments.toArray() );


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 1:55 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
forget about this, I just used linked hash set.


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