-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Cannot filter a Set object
PostPosted: Wed Sep 28, 2005 1:00 pm 
Newbie

Joined: Wed Sep 28, 2005 1:05 am
Posts: 5
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 1:31 pm 
Newbie

Joined: Wed Sep 28, 2005 1:05 am
Posts: 5
By changing the query and adding the new line #6:

session.createCriteria(Products.class)
#1: .createCriteria("ic", "ic")
#2: .createCriteria("portIcMappingsSet")
#3: .createCriteria("pTax")
#4: .createCriteria("portals")
#5: .add(Expression.eq("portalId", portalId))
.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
.list();

This would return a lits of Hashmaps with 2 elements: this (for products) and pTax which would be only one element.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.