-->
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.  [ 2 posts ] 
Author Message
 Post subject: hibernate query return some elements twice
PostPosted: Tue Mar 29, 2005 5:05 am 
Newbie

Joined: Wed Oct 20, 2004 6:22 am
Posts: 9
Hi all, I am having a problem with a simple query. I want to retreive all the region of my database. When I run the sql generated it works fine. When I read the list that hibernate gives me, it has some elements twice in the list. Anyone has any idea about what is happening?

Hibernate version:
2.1.7
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping >

<class name="com.roche.dss.extreportdomainmodel.RegionDropDown" table="REGIONS_LU">

<composite-id>
<key-property name="regionCode" column="REGION_CODE"/>
<key-property name="countryCode" column="COUNTRY_CODE"/>
</composite-id>

<property name="description"
type="string"
column="DESCRIPTION"
length="50"/>

<property name="activeFlag"
type="string"
column="ACTIVE_FLAG"
length="1"/>

</class>

</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():

public List getRegionList() {
Session session = HibernateUtil.getSession();
List regionList = null;
try {
regionList = session
.find("from RegionDropDown region where region.activeFlag = 'Y' order by region.description");
} catch (HibernateException e) {
throw new DataAccessException(e);
}
return regionList;
}


Name and version of the database you are using:
oracle9i
The generated SQL (show_sql=true):
Hibernate: select regiondrop0_.REGION_CODE as REGION_C1_, regiondrop0_.COUNTRY_CODE as COUNTRY_2_, regiondrop0_.DESCRIPTION as DESCRIPT3_, regiondrop0_.AC
TIVE_FLAG as ACTIVE_F4_ from REGIONS_LU regiondrop0_ where (regiondrop0_.ACTIVE_FLAG='Y' ) order by regiondrop0_.DESCRIPTION


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 29, 2005 10:38 am 
Newbie

Joined: Wed Oct 20, 2004 6:22 am
Posts: 9
I think it is a problem from my equals and hashCode method ... I can't see the problem..
Here are the 2 methd of my class

public boolean equals(Object other) {
if (this == other)
return true;
if (!(other instanceof RegionDropDownAbstract))
return false;
final RegionDropDownAbstract reference = (RegionDropDownAbstract) other;
if (!regionCode.equals(reference.getRegionCode())) return false;
if (!countryCode.equals(reference.getRegionCode())) return false;
return true;
}

public int hashCode() {
return (regionCode+countryCode).hashCode();
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.