I have a 4 tables which I would like to join and get the output.
Hibernate version : 3.0
Mapping documents: :
1:
<class name="Products" table="products">
<many-to-one name="ic" column="ic_category_id" class="ICTax" />
</class>
2:
<class name="ICTax" table="ic_tax">
<set name="portIcMappingsSet" inverse="true">
<key column="ic_category_id"/>
<one-to-many class="PIMappings"/>
</set>
</class>
3:
<class name="PIMappings" table="p_i_mappings">
<many-to-one name="ic" column="ic_category_id" class="ICTax" not-null="true" />
<many-to-one name="pTax" column="p_category_id" class="PTaxonomy" />
</class>
4.
<class name="PTaxonomy" table="p_tax">
<many-to-one name="portals" column="p_id" class="Port" not-null="true" />
<set name="plMappingsSet" inverse="true">
<key column="p_category_id"/>
<one-to-many class="PIMappings"/>
</set>
</class>
Code between sessionFactory.openSession() and session.close():
I wrote this query to join on these tables:
session.createCriteria(Products.class)
#1: .createCriteria("ic", "ic")
#2: .createCriteria("portIcMappingsSet", "pim")
#3: .createCriteria("pTax", "pt")
#4: .createCriteria("portals", "port")
#5: .add(Expression.eq("portalId", portalId))
.list();
The problem I am facing is : The portIcMappingsSet is not getting filtered as per the joins I am making after line #3 in the above criteria query. So the set returns to me all the combinations of ic in "PIMappings" table for the ic_category_id. But I want the set to only return one row after the join is made and for the portalId specified.
I have tried to make this as simple as possible. Please let me know if I am doing something wrong in my query and if I can filter the Set object.
Thanks in adv,
Harsha
|