-->
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.  [ 5 posts ] 
Author Message
 Post subject: Select just collection and a couple properties from object?
PostPosted: Wed Apr 02, 2008 8:10 pm 
Newbie

Joined: Fri Mar 24, 2006 2:07 pm
Posts: 8
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)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 03, 2008 4:28 pm 
Newbie

Joined: Fri Mar 24, 2006 2:07 pm
Posts: 8
Don't have an answer, but just another bit of information:

If I load the whole object instead of trying to just load bits of it out into an object array the map collection loads just as I would expect. This seems to validate that I have the .hbm.xml file set up correctly and that I just can't work out the magic HQL that I need to pull out just the collection.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 04, 2008 5:04 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Quote:
"select affProd.code, affProd.name, affProd.defaultPricing, affProd.core from AffiliateProductData affProd inner join affProd.defaultPricing where order by affProd.core desc,affProd.name"


U seem to be selecting affProf.core which is not a part of the mapping file. That could be a problem. Or is it just a spelling mistake while posting?

Your query should be

Code:
"select affProd.code, affProd.name, affProd.defaultPricing,  from AffiliateProductData  affProd  inner join affProd.defaultPricing  where order by affProd.code desc,affProd.name"

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 04, 2008 10:40 am 
Newbie

Joined: Fri Mar 24, 2006 2:07 pm
Posts: 8
Just a slip of me trying to simplify my example a little. The part of the query it freaks out on is the affProd.defaultPricing in the select section. I can change it to select the elements affProd.defaultPricing.elements but then I get all the elements jammed into the result Object[] with no keys to the map anywhere.

I have been working around this my loading the whole object and lazy loading everything it is associated with then forcing the load when I need the object to hold certain bits of data (via join fetch) but that leads to a bit of a mess when outside the session it is tricky to know if something has been loaded or not. Hibernate.isInitialized works as advertised, but it all gets a little fiddly.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 3:22 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Are your java classes properly created? Can u share them?

_________________
Sukirtha


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.