-->
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: Hibernate returns duplicate results
PostPosted: Mon Aug 14, 2006 10:09 am 
Newbie

Joined: Mon Aug 14, 2006 9:47 am
Posts: 2
Hi

I am experiencing a problem with Hibernate whereby a call to the DAO method I have inserted below returns duplicate results. The query should return five unique results, however, the returned list contains five references to the same object. We are currently using Hibernate 3.0.5. The same error occurs when I do a HQL query. Does anyone perhaps know what I am doing wrong? Any help would be appreciated!

I have inserted a copy of the Hibernate mapping file we use below the method.

public List findAfterDate(Date d, String[] batchNumbers){
Session session = HibernateUtil.currentSession();

try {
Criteria criteria = session.createCriteria(EctBatchHistory.class);
criteria.add(Expression.ge("timedate", d));
criteria.add(Expression.ne("description", "Batch(es) successfully created."));
criteria.add(Restrictions.in("batch", batchNumbers));
criteria.addOrder(Order.asc("timedate"));
List results = criteria.list();
return results;
} catch(Exception e){
e.printStackTrace();
return new ArrayList();
}
finally {
HibernateUtil.closeSession();
}
}


<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.EctBatchHistory" table="hist" schema="dbo" lazy="false">
<id name="timedate" column="timedate" type="date" >
<generator class="assigned"/>
</id>
<property name="resellerId" column="reseller_id" type="integer" />
<property name="description" column="description" type="string" />
<property name="batch" column="batch_id" type="string" />
</class>
</hibernate-mapping>

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 14, 2006 10:24 am 
Newbie

Joined: Sun Aug 13, 2006 3:35 am
Posts: 6
Hi
This happens with in case you have 1-M or M-M and you are using fetching techniques.
The strategy is to convert all the results set - into Set ( containing unique results ) and then convert back to list.

Khurram Samad


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 14, 2006 11:05 am 
Newbie

Joined: Mon Aug 14, 2006 9:47 am
Posts: 2
Hi Khurram

Thanks for the reply. We have used that solution for another problem where we had a 1-1 and a 1-M relationship that returned duplicates.

With the current problem we do not have any 1-1, 1-M or M-M relationships defined in the mapping file, yet it still returns duplicates.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 14, 2006 12:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
look at your id and think it through what type="date" means for a id column that most likely contain timestamps ;)

_________________
Max
Don't forget to rate


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.