-->
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.  [ 1 post ] 
Author Message
 Post subject: N - 1 composite element filter
PostPosted: Wed Feb 09, 2011 11:29 am 
Newbie

Joined: Wed Feb 09, 2011 11:09 am
Posts: 2
Hi forum!

I need some lights in order to follow my way.
I have Category entity that contains CategoryDescriptions. I've mapped them as composite-element bag collection:
Code:
<class name="...entities.Category" table="CATEGORY">
      <id column="ID" name="id" type="int" unsaved-value="-1">
         <generator class="identity"></generator>
      </id>
      ...
      <bag name="descriptions" table="CATEGORY_DESCRIPTION"
         lazy="true">
         <key column="CATEGORY_ID"></key>
         <composite-element
            class="com.gmsoft.middle.entities.CategoryDescription">
            <many-to-one name="language"
               class="com.gmsoft.middle.entities.Language" column="LANGUAGE_ID">
            </many-to-one>
                                ...
            <property name="description" column="DESCRIPTION"
               type="string">
            </property>
         </composite-element>
      </bag>
   </class>

   <class name="...entities.Language" table="LANGUAGE">
      <id column="ID" name="id" type="int" unsaved-value="-1">
         <generator class="identity"></generator>
      </id>
      ...
   </class>


For example, imagine that I have a category with id = 1, and this one contains three descriptions, one in English, another in Spanish and one German. When my website is displayed to the user, the contents are only shown in one language and therefore I would like to obtain only the corresponding description (translation) when I need to access to the database.

Currently, if I get a category, the all descriptions(translations) are also retrieved with it.

So I would need to know how to filter these descriptions in order to get only the descriptions of a language. That is, obtain the Category with only one description on the collection.

I tried to implement it using HQL, but I am saturated:

Code:
   public List<Category> getRootCategories(Language language) {
      return this.session.createQuery("from Category cat " +
                           "inner join cat.descriptions descs " +
                           "inner join descs.language langs " +
                           "where langs.id = 1").list();
      /*return this.session.createCriteria(Category.class)
         .add(Restrictions.isNull("parent"))
         .add(Restrictions.eq("descriptions.language", language))
            //.add(Restrictions.eq("language", language))
         .list();*/
   }


Can you help me, please?
Thanks for all in advanced.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.