-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate Object return Duplicates
PostPosted: Tue Jul 03, 2007 9:44 pm 
Beginner
Beginner

Joined: Tue May 08, 2007 1:20 pm
Posts: 24
I am using Spring HibernateTemplate findByNamedQuery method to load the object which returns duplicate records .

Here is my NamedQuery which loads the Buildings object

Code:
<query name="findBuildings">
<![CDATA[
select DISTINCT buildings from com.XXX.model.Building buildings order by buildings.building
]]>
</query>

The query works fine but it populates the dropdown with duplicate records

Wondering why DISTINCT is not working so i use subselect which doesnt work. hen i finally tried this query which works but it doesnt return objects

Code:

select buildings.bldgId, buildings.building
            from com.XXX.model.Building buildings
            group by buildings.bldgId, buildings.building
            order by buildings.building



Any pointers/suggestions on how to avoid loading Hibernae Object without duplicate records will be highly appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 04, 2007 12:55 am 
Regular
Regular

Joined: Wed Apr 25, 2007 11:44 pm
Posts: 59
check you query

and it wont be populating duplicate records; the object id of the duplicate records you see will be the same


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 04, 2007 5:45 pm 
Beginner
Beginner

Joined: Tue May 08, 2007 1:20 pm
Posts: 24
Hi msj4u
Thanks for quick response. You are right my query doesnt return duplicates. Infact i wrote the query in such a fashion that it doesnt written duplicates, i verified this by running the query at database

I didnt understood
Quote:
the object id of the duplicate records you see will be the same

Could you please explain

Also please note that i am retrieving data from single object, so i used DISTINCT which didn't worked . I am using Hibernate 3.2

I rewrote the query with different permutations & combinations but alwways it returns duplicates
Code:
select DISTINCT b from com.boeing.nmt.nams.model.NamsBuilding b where b.building in
            (select buildings.building
            from com.boeing.nmt.nams.model.NamsBuilding buildings
            group by buildings.bldgId, buildings.building)           
            order by b.building

I put the following snippet in JSF backing bean as suggested in Hibernate forums which didnt worked
Code:
//      at this point, list may contain duplicates.
//      remove duplicates if any
      Set setItems = new LinkedHashSet(Building);
      Building.clear();
      Building.addAll(setItems);

So i guess i tried everything. Pl let me know if i am missing something


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 12:13 am 
Regular
Regular

Joined: Wed Apr 25, 2007 11:44 pm
Posts: 59
Code:
List lst = query.list();
for(int loop=0; loop<lst.length; ++loop) {
    System.out.println(lst.get(loop));
}


execute this and see that the output contains the repetitions or not


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