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]