I have a bidirectional mapping that looks like this;
Parent:
<set lazy="false" inverse="true" name="child">
<key column="iid_parent"/>
<one-to-many class="my.dom.Child"/>
</set>
Child:
<many-to-one column="iid_parent" name="parent" class="my.dom.parent"/>
I need to run a query like this;
select parent from t_parent where parent.id in (x,y) and child.childType != ''
So I have used;
List results = session.createCriteria(Parent.class)
.add(Restrictions.in("id", ids))
.createCriteria("child","kids")
.add(Restrictions.ne("kids.childType",""))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.list()
and a similar HQL query.
However, I get back child elements with childTypes = '' which I tried to filter.
I have been able to get the desired result by adding
where="childtype != '' "
to the parent mapping.
Is there a way to do this in HQL or a criteria query without adding the where clause to the mapping and without defining a composite key?
Hibernate 3.2.2
|