-->
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.  [ 4 posts ] 
Author Message
 Post subject: HQL query problem
PostPosted: Thu Apr 22, 2010 4:15 am 
Newbie

Joined: Thu Apr 22, 2010 4:08 am
Posts: 2
Hi all,

I'm using this hql query for my filters. Query perfectly working except width (string) part.

Here is the query,

Code:
public IList<ColorGroup> GetDistinctColorGroups(int typeID, int finishID, string width)
            {
                string queryStr = "Select distinct c from ColorGroup c inner join c.Products p " +
                                  "where p.ShowOnline = 1 ";


                if (typeID > 0)
                    queryStr += " and p.ProductType.ID = " + typeID;

                if (finishID > 0)
                    queryStr += " and p.FinishGroup.ID = " + finishID;

                if (width != "")
                    queryStr += " and p.Size.Width = " + width;

                IList<ColorGroup> colors = NHibernateSession.CreateQuery(queryStr).List<ColorGroup>();

                return colors;
            }


ProductType and Size have same mappings and relations.

This is the error;

NHibernate.QueryException: illegal syntax near collection: Size [Select distinct c from .Domain.ColorGroup c inner join c.Products p where p.ShowOnline = 1 and p.ProductType.ID = 1 and p.FinishGroup.ID = 5 and p.Size.Width = 4]

Any ideas ?


Top
 Profile  
 
 Post subject: Re: HQL query problem
PostPosted: Fri Apr 23, 2010 3:04 am 
Beginner
Beginner

Joined: Fri Feb 27, 2009 6:07 am
Posts: 38
Location: Moscow,Russia
Show mapping file for ColorGroup .


Top
 Profile  
 
 Post subject: Re: HQL query problem
PostPosted: Sun Apr 25, 2010 2:41 am 
Newbie

Joined: Thu Apr 22, 2010 4:08 am
Posts: 2
kir wrote:
Show mapping file for ColorGroup .


Code:
<property name="Name" />

        <bag name="Products" generic="true" inverse="true" cascade="none">
            <key column="ColorGroupID" />
            <one-to-many class="...Domain.Product, ...Domain" />
        </bag>


and Product's mappings

Code:
<component name="Size" lazy="false" class="...Domain.Size, ...Domain">
            <property name="Width" />
            <property name="Length" />
            <property name="Thickness" />
        </component>

<many-to-one name="ProductType" class="...Domain.ProductType, ...Domain" column="ProductTypeID" not-null="true" ></many-to-one>
<many-to-one name="FinishGroup" class="...Domain.FinishGroup, ...Domain" column="FinishGroupID" not-null="true" ></many-to-one>


Top
 Profile  
 
 Post subject: Re: HQL query problem
PostPosted: Mon Apr 26, 2010 4:15 am 
Beginner
Beginner

Joined: Fri Feb 27, 2009 6:07 am
Posts: 38
Location: Moscow,Russia
Code:
session.CreateQuery("select distinct c from ColorGroup c inner join c.Products p where p in (select p2 from Product p2 where p2.Size.Width=10)");


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