-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL Query - Retrieving rows with specific language
PostPosted: Thu Feb 14, 2008 11:11 am 
Newbie

Joined: Thu Feb 14, 2008 10:47 am
Posts: 2
Hi everybody,

As you will probably guess, I am new to Hibernate... Shame on me.
I have a question concerning HQL.
I need to do a query to my database but can't succeed in HQL. It works fine in SQL.

The 'simplified' context is:
I have 2 tables:
- Collections
- Collections_Content

One 'Collections' can have between 1 and X 'Collections_Content'.
Here is the 'Collections' mapping file:
Code:
<hibernate-mapping>
    <class name="Collections" table="COLLECTIONS">
               
        <id name="coll_id" column="c_uid" type="long">
            <generator class="increment"/>
        </id>
        <property name="identifier" type="string"/>
        <property name="searchable" type="boolean"/>
        <property name="harvestable" type="boolean"/>
        <property name="theme" type="string"/>
        <property name="publisher" type="string"/>
        <property name="country" type="string"/>
        <property name="thumbnail" type="string"/>
        <property name="belongs_to" type="string" />
        <property name="type" type="string" />

        <bag name="collectionsSearch" inverse="true" order-by="DATE_TIME" cascade="all">
            <key column="c_uid" />
            <one-to-many class="CollectionsSearch" />
        </bag>

    </class>
</hibernate-mapping>



And here the Collections_Content mapping file:

Code:
<hibernate-mapping>
    <class name="CollectionsContent" table="COLLECTIONS_CONTENT">
        <id name="cc_uid" column="cc_uid" type="long">
            <generator class="increment"/>
        </id>
        <many-to-one name="collections" column="c_uid" not-null="true" class="Collections" />
        <property name="language" type="string"/>
        <property name="title" type="string"/>
        <property name="description" type="string"/>
    </class>
</hibernate-mapping>




I want to retrieve information from both table, but just ONE ROW per Collections.coll_id.
Why ? Because I want to retrieve one 'Collections' with its 'Collections_Content' information in a SPECIFIC language, and if this SPECIFIC language doesn't exist, I need to switch it to English.
And not 6 rows of the same Collections.coll_id with different languages/title/description.

For the moment, I can, of course, access both tables, in a specific language using something like:

Code:
getHibernateTemplate().find("from Collections c" +
                " left join c.collectionsContent cc" +
                " WITH (cc.language='" + language + "')");

where language can be 'en', 'de', 'nl', ...

But sometimes, those languages don't exist for that specific 'Collections', and then I would need to get the row anyway but with language switched to English.

I have no idea how to make this possible in Hibernate...

Could you please help me on this one ?

Thanks a lot,
Yoann


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 15, 2008 6:38 am 
Newbie

Joined: Thu Feb 14, 2008 10:47 am
Posts: 2
Too bad nobody could answer...

I haven't found a solution for the query ...

So what I did is to iterate through the List I got with a query retrieving 2 rows per 'Collections' with language=XX or language=EN, and then picking up things needed and leaving other things out.

Cheers,
Yoann


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