-->
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.  [ 1 post ] 
Author Message
 Post subject: Select distinct
PostPosted: Thu Apr 21, 2005 6:10 am 
Beginner
Beginner

Joined: Wed Mar 30, 2005 5:41 am
Posts: 40
Hi,

I am trying to retrieve the possible "titles" of the persons in my database :
Code:
Collection titles = DefaultDAO.instance().select( "select distinct p.title from PersonData p where p.title is not null and p.title <> ''" );
for ( Iterator iter = titles.iterator(); iter.hasNext(); )
{
   Object element = (Object)iter.next();
   System.out.println( "-" +element );
}


The output is :
-Mademoiselle
-Monsieur
-Madame
-Madame et Monsieur
-Monsieur

But I was expecting :
-Mademoiselle
-Monsieur
-Madame
-Madame et Monsieur

I have executed the generated sql (see below) directly in MySQL and the result was ok.

Why does the collection contains "Monsieur" twice ?

Best regards
Lilian


Hibernate version:
3.0

Mapping documents:
PersonData.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>

<class
name="bab.admin.model.persistent.PersonData"
table="t_person" >

<id name="id" column="partyId" type="java.lang.Integer">
<generator class="assigned">
</generator>
</id>

<property name="title" />


</class>

</hibernate-mapping>


Name and version of the database you are using:
MySQL 4.1

The generated SQL (show_sql=true):
select distinct persondata0_.title as col_0_0_ from t_person persondata0_ where ((persondata0_.title is not null) and persondata0_.title<>'')[/code]


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

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.