Hibernate version: 3.2.0 rc2
Mapping documents:
<hibernate-mapping>
<class name="com.softbare.vo.Prescription" table="prescription">
<id name="id" column="id" unsaved-value="null">
<generator class="increment"/>
</id>
<set name="treatments" table="treatment" inverse="true" cascade="save-update">
<key column="prescription_id"/>
<one-to-many class="com.softbare.vo.Treatment"/>
</set>
</class>
</hibernate-mapping>
Code to fetch prescriptions where the treatment have a null property
public List findTreatedPrescriptions() {
/*
SELECT p.id, p.date
FROM prescription p, treatment t
WHERE p.id = t.id
AND t.attest_id = null;
*/
String hqlQuery = "select distinct p from Prescription p, Treatment t " +
"inner join t.prescription " +
"where t.attest is null";
HibernateTemplate hibernateTemplate = getHibernateTemplate();
return hibernateTemplate.find(hqlQuery);
}
Problem
I get a List of prescriptions back; but each Prescription in the list contains all treatments where I only want to treatments who have a null property. Namely where the attest is null
What's the best way to achieve this kind of functionality?? filters? lazy=extra, ... ????
Please help me out here!!
|