Hi,
I have a mapped object named TemplateValue and a many to many association with Template1Value. When I create my list using criteria it's fine. I can restrict TemplateValue list with a Template1Value property.
But when I access the collection of Template1Value, there is no restriction.
TemplateValue.hbm.xml
<class name="TemplateValue" table="TEMPLATE" >
<id name="id" column="ID">
<generator class="increment"/>
</id>
<property name="title"/>
<set name="templates1" table="TEMPLATE_TEMPLATE1" lazy="false" >
<key column="TEMPLATE_ID"/>
<many-to-many column="TEMPLATE1_ID" class="Template1Value"/>
</set>
</class>
Criteria criteria = this.session.createCriteria(TemplateValue.class);
Criteria criteriaTemplate1 = criteria.createAlias("templates1", "t1");
criteriaTemplate1.add( Restrictions.like( "t1.title", "toto"));
List list = criteria.list();
for (int i=0;i<list.size();i++){
TemplateValue templateValue = (TemplateValue) list.get(i);
log.debug("id:"+templateValue.getId());
log.debug("title:"+templateValue.getTitle());
//Ok
Iterator it=templateValue.getTemplates1().iterator(); while (it.hasNext()){ Template1Value template1Value = (Template1Value) it.next(); log.debug("\t id:"+template1Value.getId()); log.debug("\t title:"+template1Value.getTitle()); //template1Value is not in my restriction }
}
At the first level, templateValue is ok, but the associated objects template1Value are not filtred. How can I realize the restriction ?
THANKS
|