• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DetachedCriteria returns duplicate results for one-to-many association

 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

The subject might not be a meaning full, but I could not find a better explanation of the problem I am gonna describe.

Isn't DetachedCriteia for an Entity supposed to fetch records only from the table the Entity is representing. For example, in my case, I've got two entities say, X and Y such that there is one to many relationship between the two.

In X entity, I have a Set of Y's, and each Y contains an X.

The fetch type strategy defined for Y in X is EAGER.

Now, if I create a DetachedCriteria for X using



And using this code



(Yes, I am using Spring)

I get duplicate records, I mean all the X's and the ones from Y's as well. In a sense, I am getting records from table represented by X and Y both.

And if I change the fetch type strategy to LAZY, I don't get duplicate X's from the result list.

Can some please explain the role of DetachedCriteria here?


 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, but does the question, by any chance, make sense? I'm still wondering as to what's causing this behaviour.
 
Randeep Singh Arora
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Girish,

Can you PM me link to running sample of your problem.May be I can help you with this problem.

Regards
Randeep
 
Renato Scott
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the solution:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic