-->
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.  [ 6 posts ] 
Author Message
 Post subject: referencing java.util.map key in hql
PostPosted: Tue Dec 05, 2006 12:26 pm 
Beginner
Beginner

Joined: Sat Feb 18, 2006 6:24 am
Posts: 23
Hi,

I have object called Article which holds java.util.map property.

Map property is mapped like this:
Code:
<map name="translations" table="i18n_content" lazy="true">
         <key column="articleID" />
         <index column="language_code" type="string"/>
         <composite-element class="ArticleTranslation">
         
            <property name="title">
               <column name="k_title" length="255" not-null="true"/>
            </property>


Now, I want to query only those Article objects which have certain key in map.

I thought to solve this with join fetching using query like:

Code:
from Article as article
    left join article.translations as translation
        where .....


thats where I realized that I don't know how to reference to map key in HQL.
Can somebody help me about this problem? Is this even possible?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 05, 2006 6:01 pm 
Newbie

Joined: Thu Nov 17, 2005 1:44 pm
Posts: 6
Hi,

I've never found how/if this could be done. I've always had to do it with SQL directly. I don't know if there's a recently added feature allowing that though.

_________________
Thank you for a Great product!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 7:27 am 
Beginner
Beginner

Joined: Sat Feb 18, 2006 6:24 am
Posts: 23
fdurden wrote:
Hi,

I've never found how/if this could be done. I've always had to do it with SQL directly. I don't know if there's a recently added feature allowing that though.


Hmmm... somebody from Hibernate team? Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 2:59 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
If I understand what you are saying, you should be able to simply say something like "where translation.articleId = :articleId"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 3:06 pm 
Beginner
Beginner

Joined: Sat Feb 18, 2006 6:24 am
Posts: 23
hibernate_user wrote:
If I understand what you are saying, you should be able to simply say something like "where translation.articleId = :articleId"


More something like this: where article.translations.key = :languageCode
and article.translations.key should be replaced with reference to map key.
More I read HIbernate documentation more I believe that such thing is not possible :-(


Top
 Profile  
 
 Post subject: Re: referencing java.util.map key in hql
PostPosted: Wed Dec 13, 2006 6:12 am 
Newbie

Joined: Fri Dec 08, 2006 12:00 pm
Posts: 1
bigor wrote:
Hi,
I thought to solve this with join fetching using query like:

Code:
from Article as article
    left join article.translations as translation
        where .....


thats where I realized that I don't know how to reference to map key in HQL.
Can somebody help me about this problem? Is this even possible?


You can try
Code:
from Article as article where :languageCode in indices(article.translations)


Hibernate will generate a subquery for the map index. See section 14.9 of the reference doc for more indexed collection fuctions.


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