-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Duplicate Objects returned instead of different
PostPosted: Wed Aug 19, 2009 8:57 am 
Newbie

Joined: Wed Aug 19, 2009 3:26 am
Posts: 2
Hi there,

I have a criteria where I'm querying to get 5 rows. Hibernate createCriteria is returning first object meeting my restrictions 5 times instead of 5 different objects.

Elaboration(if required):
createCriteria is used with a single restriction, equivalent to "select * from <table> where id='100'"
I know in the data base, there are 5 rows with the id 100,
For this criteria, Hibernate is returning the single object 5 times having information of first row. I have verified by printing the hash code for all the 5 items and its seen that they all are same.

Any ideas?


Top
 Profile  
 
 Post subject: Re: Duplicate Objects returned instead of different
PostPosted: Wed Aug 19, 2009 9:13 am 
Newbie

Joined: Wed Aug 19, 2009 8:49 am
Posts: 5
Hi, i go through a problem like yours, does that object has any association (like OneToMany ) ?

see this post Elementos Duplicados em Criterias do Hibernate

when hibernate fetch the associations , it ends up with a table with associations and for each element in the association it ends up with the same root entity

that post suggest to use a Set implementation to discard duplicities or force hibernate to do a DISTINCT select in the entity (best approach)

i think it may help


Top
 Profile  
 
 Post subject: Re: Duplicate Objects returned instead of different
PostPosted: Wed Aug 19, 2009 11:57 pm 
Newbie

Joined: Wed Aug 19, 2009 3:26 am
Posts: 2
Thanks for the response felipebn,

In my case I have many to many association with other table, but here my problem is not about the distinct root entiry. I have tried setting the distinct key, the query returned just one object, instead of 5 different objects.

What I mean is, If its the problem of Distinct Root entity, considering my above example, I should have got all the 5 rows duplicated to number of times the associated table entry, Say if the same restriction key entries are twice in the associated table, I should have got totally 10 rows as a result of query, i.e 5 different objects duplicated twice each.
But here, I'm getting just 5 rows, all are duplicates of first row.

Suggestions?


Top
 Profile  
 
 Post subject: Re: Duplicate Objects returned instead of different
PostPosted: Thu Aug 20, 2009 7:19 am 
Newbie

Joined: Wed Aug 19, 2009 8:49 am
Posts: 5
Ok, i understand it now... uhmm..

can you post a sample to illustrate your object and your criteria ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.