-->
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: HQL: order all items by a specific item in its map
PostPosted: Thu May 14, 2009 11:54 pm 
Newbie

Joined: Thu May 14, 2009 11:48 pm
Posts: 6
Hi,

I am quite new to Hibernate and currently struggling a bit with HQL. I have the following mapping and would like to get all "Industry" entities ordered by the "translation" for a given "culture_id"

Code:
<?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>


I tried the following:
Code:
from Industry industry order by elements(industry.AllNames[:lcid])

but it does not work...

Thanks for any help!!


Top
 Profile  
 
 Post subject: Re: HQL: order all items by a specific item in its map
PostPosted: Fri May 15, 2009 1:48 pm 
Senior
Senior

Joined: Thu Jan 08, 2009 3:48 pm
Posts: 168
Quote:
name="Domain.Industry, Core"

This looks wrong

I would usually write that kind of query like

from Industry industry where industry.AllNames.culture_id = :clId order by industry.AllNames.translation


Top
 Profile  
 
 Post subject: Re: HQL: order all items by a specific item in its map
PostPosted: Sun May 17, 2009 11:58 pm 
Newbie

Joined: Thu May 14, 2009 11:48 pm
Posts: 6
thanks ... i have tried

"from Industry industry where industry.AllNames.culture_id = :lcid order by industry.AllNames.translation"

but i am getting the following error:

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

i do not know why it does not work ...
btw the name is actually ITAssessments.Core.Domain.Industry, ITAssessments.Core ... so this should not be an issue


Top
 Profile  
 
 Post subject: Re: HQL: order all items by a specific item in its map
PostPosted: Mon May 18, 2009 6:21 am 
Senior
Senior

Joined: Thu Jan 08, 2009 3:48 pm
Posts: 168
try replacing the industry.AllNames.translation with a left outer join between industry and Allnames

from ITAssessments.Core.Domain.Industry industry
left outer join industry.AllNames allNames
where allNames.culture_id = :lcid order by allNames.translation


Top
 Profile  
 
 Post subject: Re: HQL: order all items by a specific item in its map
PostPosted: Tue May 19, 2009 12:28 am 
Newbie

Joined: Thu May 14, 2009 11:48 pm
Posts: 6
Tried that but it results in the following error:

Code:
Nhibernate.QueryException : cannot dereference scalar collection element: culture_id [from ITAssessments.Core.Domain.Industry industry left outer join industry.AllNames allNames where allNames.culture_id = :lcid order by allNames.translation]


i am new to hibernate so it is really hard for me to find out what the problem is. I have seen something about index() and elements() function .. should this be used in that case maybe?

i really appreciate your help...


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.