• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Duplicate Row IN Hibernate Fetch

 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • 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
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Ganesh Shirsat
Ranch Hand
Posts: 33
Google Web Toolkit Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
bala rimmalapudi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Hi Bala,

I got the issue.

My DB has duplicate rows.

Thanks a lot for your valuable time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic