Details below, but basically I am trying to work out how to select a collection from an object in HQL without getting the whole object. I have an object A with a map of children (KEYOBJ, VALUEOBJ) and A contains various other properties. In this particular case I want to just select A.children and get back a Map object. If I use HQL the way I assume it should work I get the error:
expecting 'elements' or 'indices' after: id
Which implies to me I can only select the values or keys of the map and not the whole map.
Any thoughts on how I can select just the collection and some of the properties with HQL?
Hibernate 2.1
Code:
HQL:
"select affProd.code, affProd.name, affProd.defaultPricing, affProd.core from AffiliateProductData affProd inner join affProd.defaultPricing where order by affProd.core desc,affProd.name" ,
Mapping Doc:
<class name="ProductData" table="affiliate_product" >
<id name="code" column="code">
<generator class="assigned"/>
</id>
<property name="name" not-null="true"/>
<map name="defaultPricing" table="aff_default_pricing" order-by="tier_id asc" cascade="all">
<key column="code" />
<index-many-to-many column="tier_id" class="Tier"/>
<many-to-many column="pricing_mechanism_id" class="PricingMechanismData"/>
</map>
</class>
<class name="PricingMechanismData" table="pricing_mechanism">
<id name="pricingMechanismId" column="pricing_mechanism_id">
<generator class="sequence">
<param name="sequence">pricing_mechanism_id</param>
</generator>
</id>
<joined-subclass name="FlatRatePricing" table="pricing_flat_rate" >
<key column="pricing_mechanism_id"/>
<property name="rate"/>
</joined-subclass>
<joined-subclass name="PercentageRatePricing" table="pricing_percentage_rate" >
<key column="pricing_mechanism_id"/>
<property name="rate"/>
</joined-subclass>
</class>
<class name="Tier" table="aff_default_pricing_tier">
<id name="tierId" column="tier_id" type="long">
<generator class="sequence">
<param name="sequence">seq_aff_default_pricing_tier_id</param>
</generator>
</id>
<property name="tier_name" not-null="true" type="string"/>
</class>
net.sf.hibernate.QueryException: expecting 'elements' or 'indices' after:
id [select affProd.code, affProd.name, affProd.defaultPricing, affProd.core
from com.credit.affiliate.product.data.AffiliateProductData affProd inner
join affProd.category categoryObj inner join affProd.defaultPricing where
categoryObj.category=? order by affProd.core desc,affProd.name]
at net.sf.hibernate.collection.CollectionPropertyMapping.toType(CollectionPropertyMapping.java:53)
at net.sf.hibernate.hql.PathExpressionParser.getPropertyType(PathExpressionParser.java:249)
at net.sf.hibernate.hql.PathExpressionParser.end(PathExpressionParser.java:288)
at net.sf.hibernate.hql.SelectPathExpressionParser.end(SelectPathExpressionParser.java:14)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
at net.sf.hibernate.hql.SelectParser.token(SelectParser.java:170)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:114)
at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:295)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1572)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1531)