• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Duplicate Row IN Hibernate Fetch

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The above query is returning a list which contains a duplicate object.
Example: Suppose if it has to return 9 objects it is retuning 10 instead. One object is being duplicated.

But when I changed the code as below. It is returning exactly 9 objects.




Why hibernate is returning duplicate rows and is there any other way i can eliminate duplicate rows instead of changing list to set?

NOTE: I am very beginner in hibernate. Please help me out
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate probably works the same in both cases. The difference is that Set can keep only one copy of identical items. Therefore when Hibernate puts two identical items into a List, both will remain, whereas when it puts them into a Set, only one of them will remain there.
 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

when Hibernate puts two identical items into a List



my question is why hibernate returns two items when the db contains only one?
 
Ranch Hand
Posts: 33
Google Web Toolkit Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

have you run the hibernate generated query in sql console?



may query generated by hibernate will cause the two rows.

Second times it work because Set doesnot allowed duplicate record.
 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I didn't run in sql console.

Actaully I don't know how to run this Hibernate query.

Can you please help me?

And suppose if it returned two rows , how to modify my query such that it returns only one
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
Better you just check the converted SQL statement by adding the below statement in your Hibernate configuration file,

<property name="show_sql">true</property>

The above statement in hibernate configuration file, results in writing the generated SQL ststement to standard output console, so that you can find what exactly is causing the problem.
 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi bala
ya exactly i have tried the same.

When I executed the query I got correct no.of rows. It does't have any dupliates
 
bala rimmalapudi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ramesh,
I didn't get your point.Try to use the above configuration with Set and after that try with List and make sure you make a note of the SQL in both the cases and check the results.



 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bala,

I got the issue.

My DB has duplicate rows.

Thanks a lot for your valuable time.
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic