Hey,
I'm getting a strange list size using HQL which I just don't get. When I run the generated SQL (which I can see is used in my debugger), the database returns 3 results. However, doInHibernate(), which uses this HQL, return 7 rows, that is, it returns doubles of each row in the database.
The code including the Hql looks like that:
Code:
HibernateTemplate ht = getHibernateTemplate();
HibernateCallback callback = new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException {
String query = "from Note as note where note.agreementRef = :agreementRef and note.noteTypeRef = :noteType order by note.created desc ";
Query queryObject = session.createQuery(query.toString());
queryObject.setParameter("agreementRef", agreementRef);
queryObject.setParameter("noteType", noteType);
return queryObject.list();
}
};
List<Note> list = (List<Note>) ht.execute(callback);
The Note hbm.xml mapping file looks like that:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="what.ever.model.note" default-lazy="true">
<class name="what.ever.model.note.Note" table="NOTES">
<cache usage="nonstrict-read-write" />
<id name="id" column="ID" type="java.lang.Integer" unsaved-value="null">
<generator class="sequence">
<param name="sequence">NOTES_SEQ</param>
</generator>
</id>
<many-to-one name="noteTypeRef" column="NOTE_TYPE_ID_FK"
class="what.ever.model.note.NoteType" fetch="join" lazy="false" not-null="true" />
<many-to-one name="agreementRef" column="AGREEMENT_ID_FK"
class="what.ever.model.agreement.Agreement" fetch="select" not-null="true" />
<property name="note" column="NOTE" type="java.lang.String" />
<property name="userName" column="USER_NAME" type="java.lang.String" />
<property name="created" column="CREATED" type="java.util.Date" />
<property name="createdBy" column="CREATED_BY" type="java.lang.String" length="100" />
</class>
</hibernate-mapping>
...and I should probably add that the Agreement and NoteType hbm.xml files do not contain references to Note.
The generated SQL looks like that:
Code:
select
note0_.ID as ID29_,
note0_.NOTE_TYPE_ID_FK as NOTE2_29_,
note0_.AGREEMENT_ID_FK as AGREEMENT3_29_,
note0_.NOTE as NOTE29_,
note0_.USER_NAME as USER5_29_,
note0_.CREATED as CREATED29_,
note0_.CREATED_BY as CREATED7_29_
from
NOTES note0_
where
note0_.AGREEMENT_ID_FK=?
and note0_.NOTE_TYPE_ID_FK=?
order by
note0_.CREATED desc
I'm using Hibernate 3.2.4, Spring 2.5.5 and Oracle database 9.2.
So, any ideas why I get 7 rows instead of 3?
Thanks,
/U