Announcement Announcement Module
Collapse
No announcement yet.
Hibernate Query returns duplicate objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate Query returns duplicate objects

    I wrote the query in such a fashion that it doesnt written duplicates, i verified this by running the query at database

    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.XXX.model.Building b where b.building in 
                (select buildings.building
                from com.XXX.model.Building 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

  • #2
    What does debug info shows about actual query being performed ?

    Comment


    • #3
      And what you means by "duplicates"? Building with the same ID, or the same business key (whatever it is in your case), or the same values for all business fields? Something else?
      And can you provide mapping for building?
      And how you have obtained objects by your query? Can you provide relevent code snippet?

      Regards,
      Oleksandr

      Comment


      • #4
        Have you implemented equals and hashcode correctly?
        Last edited by karldmoore; Aug 29th, 2007, 11:00 AM.

        Comment

        Working...
        X