HQL help needed: order by item in map

103 views
Skip to first unread message

Michal

unread,
May 14, 2009, 11:03:44 PM5/14/09
to nhusers
Hi,

I have the following mapping of my "Industry" object:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Domain.Industry, Core" table="industry">

<id name="ID" unsaved-value="0">
<generator class="identity" />
</id>

<map name="AllNames"
access="nosetter.camelcase-underscore"
table="_dict_industry_name"
cascade="all-delete-orphan">
<key column="record_id"></key>
<index column="culture_id" type="Int32"></index>
<element column="translation" type="String"></element>
</map>

</class>
</hibernate-mapping>

Now I would like to query all Industries ordered by the element of a
given culture_id.
I am stuck here ... I think i am close with this, but it does not
work:

string query = "from Industry industry order by industry.AllNames
[:lcid]";
IQuery q = NHibernateSession.CreateQuery(query);
q.SetParameter("lcid", DomainCulture.Current);

Thanks guys!

abrakadabr

unread,
May 15, 2009, 6:28:49 AM5/15/09
to nhusers
from Industry industry
where index(industry) = :lcid
order by industry.AllNames

abrakadabr

unread,
May 15, 2009, 6:17:31 AM5/15/09
to nhusers
from Industry industry
where index(industry.AllNames) = :lcid
order by industry.AllNames

On 15 май, 06:03, Michal <mga...@gmail.com> wrote:
> Hi,
>
> I have the following mapping of my "Industry" object:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
>   <class name="Domain.Industry, Core" table="industry">
>
>     <id name="ID" unsaved-value="0">
>       <generator class="identity" />
>     </id>
>
>     <map name="AllNames"
>       access="nosetter.camelcase-underscore"
>       table="_dict_industry_name"
>       cascade="all-delete-orphan">
>       <key column="record_id"></key>
>       <index column="culture_id" type="Int32"></index>
>       <element column="translation" type="String"></element>
>     </map>
>
>   </class>
> </hibernate-mapping>
>
> Now I would like toqueryall Industries ordered by the element of a
> given culture_id.
> I am stuck here ... I think i am close with this, but it does not
> work:
>
> stringquery= "from Industry industryorderby industry.AllNames

Michal

unread,
May 17, 2009, 11:45:02 PM5/17/09
to nhusers
Thanks a lot abrakadabr. It looked promising but i am getting this
error

illegal syntax near collection: index [from
ITAssessments.Core.Domain.Industry industry where index
(industry.AllNames) = :lcid order by industry.AllNames]

do you have a clue?

Michal

unread,
May 17, 2009, 11:49:39 PM5/17/09
to nhusers
I have tried just ordering by the index ( from Industry industry order
by index(industry.AllNames) ) and it throws the same error:

illegal syntax near collection: index [from
ITAssessments.Core.Domain.Industry industry order by index
(industry.AllNames)]

On May 15, 5:17 pm, abrakadabr <kov...@gmail.com> wrote:

Michal

unread,
May 17, 2009, 11:51:42 PM5/17/09
to nhusers
I have tried just ordering by the index ( from Industry industry order
by index(industry.AllNames) ) and it throws the same error:

illegal syntax near collection: index [from
ITAssessments.Core.Domain.Industry industry order by index
(industry.AllNames)]

On May 15, 5:17 pm, abrakadabr <kov...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages