views:

796

answers:

1

Hi everyone,

I have an object with a map of components:

<class name="Article" table="articles">
 ...
  <map name="i18nData" table="articles_i18n">
      <key column="id" not-null="true"/>
      <map-key column="language" type="string"/>

      <composite-element class="Article$ArticleI18nData">
        <property name="displayName" type="string"/>
      </composite-element>

    </map>      

</class>

How would a HQL query look like to retrieve all "article" objects ordered by the 'displayName' property of the mapped component, mapped with a key for e.g. 'EN'?

thanks, chris

+1  A: 

Add an "order-by" attribute to the map element:

<map name="i18nData" table="articles_i18n" order-by="name asc">
  ..
</map>

Value of the attribute are database column names.

See:

  • Hibernate documentation - 6.2. Collection mappings (docs.jboss.org/hibernate/stable/core/reference/en/html/collections-mapping.html)
  • Hibernate documentation - 6.3.1. Sorted collections (docs.jboss.org/hibernate/stable/core/reference/en/html/collections-advancedmappings.html)

Sorry I'am a new user and not allowed to add real hyperlinks.

Daniel Murygin
this would only order the map entries of each article but not the order of the article objects itself.
Chris