-->
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: Help with lazy fetching - collections not initialized
PostPosted: Thu Jun 04, 2009 10:16 am 
Newbie

Joined: Thu Jun 04, 2009 10:02 am
Posts: 6
Hi all,

I guess you get a lot of questions about this, and I can understand this now, after 8 hours on work not getting any further :)
I have searched and googled forever, read articles, documentation etc. but I am still not sure, I get the core idea of this, since I cant make it work.

I have the following scenario, with databased resource bundles tied together by a one-to-many relation: localeKey --> localeMessage, where it is a o-t-m because localeMessages has a locale code, and so there are several messages, one in each language tied to one localeKey.
My mappings look like the following:

LocaleKey.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 01-08-2008 11:58:45 by Hibernate Tools 3.2.2.GA -->
<hibernate-mapping>
    <class name="com.issworld.simiss.domain.LocaleKey" table="LocaleKey" >
        <meta attribute="generated-class" inherit="false">com.issworld.simiss.domain.base.LocaleKeyBase</meta>
        <meta attribute="scope-class" inherit="false">public abstract</meta>
        <id name="localeKeyId" type="java.lang.Integer">
            <column name="LocaleKeyId" />
            <generator class="native" />
        </id>
        <many-to-one name="ressourceBundleType" class="com.issworld.simiss.domain.RessourceBundleType" fetch="select">
            <column name="RessourceBundleTypeId" not-null="true" />
        </many-to-one>
        <property name="localeKeyName" type="string">
            <column name="LocaleKeyName" length="100" not-null="true" unique="true" />
        </property>
        <property name="description" type="string">
            <column name="Description" length="500" />
        </property>
        <set name="localeMessages" inverse="true" lazy="false">
            <key>
                <column name="LocaleKeyId" not-null="true" />
            </key>
            <one-to-many class="com.issworld.simiss.domain.LocaleMessage" />
        </set>
    </class>
</hibernate-mapping>


LocaleMessage.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 01-08-2008 11:58:45 by Hibernate Tools 3.2.2.GA -->
<hibernate-mapping>
    <class name="com.issworld.simiss.domain.LocaleMessage" table="LocaleMessage" >
        <meta attribute="generated-class" inherit="false">com.issworld.simiss.domain.base.LocaleMessageBase</meta>
        <meta attribute="scope-class">public abstract</meta>
        <composite-id name="id" class="com.issworld.simiss.domain.LocaleMessageId">
           <meta attribute="generated-class" inherit="false">com.issworld.simiss.domain.base.LocaleMessageIdBase</meta>
            <key-property name="localeKeyId" type="int">
                <column name="LocaleKeyId" />
            </key-property>
            <key-property name="languageId" type="int">
                <column name="LanguageId" />
            </key-property>
        </composite-id>
        <many-to-one name="localeKey" class="com.issworld.simiss.domain.LocaleKey" update="false" insert="false" fetch="select">
            <column name="LocaleKeyId" not-null="true" />
        </many-to-one>
        <many-to-one name="language" class="com.issworld.simiss.domain.Language" update="false" insert="false" fetch="select">
            <column name="LanguageId" not-null="true" />
        </many-to-one>
        <property name="message" type="string">
            <column name="Message" length="100" not-null="true" />
        </property>
    </class>
</hibernate-mapping>


All I want to do, is to retrieve a set of localekeys from the database, with a NON-LAZY initialized set of localeMessages... I have tried several options on the <set name="localeMessages" inverse="true" lazy="false"> parameter, but none has worked for me... :( I am fetching from the database with the following HQL query:
Code:
   <query name="getLocaleKeysByFilter">
       <![CDATA[ 
         select lk
          from
           LocaleKey lk
           inner join fetch lk.localeMessages as lm
          where
            (
               lm.language.languageId = :languageId AND
               (
                  :filter='' OR
                  lk.localeKeyName like '%' + :filter + '%' OR
                  lm.message like '%' + :filter + '%'               
                )
            )
            OR
            (
               (lm.language.languageId = :editLanguageId AND lm.message='') AND
               (                               
                  :filter='' OR
                  lk.localeKeyName like '%' + :filter + '%'                             
                )
            )         
       ]]>
    </query>


It is for a online translation tool where one should be able to search for either the name of a know localekey, or what is currently saved in the corresponding localeMessage. So dont mind som much the lower part..
This returns a set of localeKeys, but when i want to iterate over the localeMessages tied to this, they are not initialized...
How come? What am I dooing wrong?

Please help me!

Thank you in advance!

Best Regards
Rasmus Hovendal, Denmark.


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.