Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One to Many relation returns duplicate parents

 
Sachin Kumar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


here this list contains duplicates of DataType, which is cartisan product as returned by query. Where I don't want duplicates of DataTypes and parent child relationship is proper.
 
John Bengler
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sachin,

thinking about this I would expect this to return multiple rows, especially if you look at the sql which is generated..

What you should do to get the DataType just once is a good question.


Have you already tried to add a "distinct" to your query? But I'm afraid even this won't do it, because in the end it is translated to sql...


On the other side there has to be a solution. If not the Join Fetch is a nice feature for ManyToOne relations, but not for OneToMany or ManyToMany relations..


John
 
John Bengler
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sachin,

I found something on the net.. looks like the "distinct" could help you:

help understanding join fetch


John
 
Sachin Kumar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks John,
unfortunately hibernate is not providing return as set to root out duplicate possiblility.
I fixed it by then by explicitly adding this list into set.
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin:

Have you tried changing this:

To this?:

John.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic