-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem, i need lazy=false with condition.
PostPosted: Fri Mar 18, 2005 3:16 pm 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
Hi all and thanks in advance !

Suppose i have 3 objects.
Menu - MenuLanguage - Language

Menu has a set of Menu and a set of MenuLanguages

Menu {
Long cdMenu
Set childMenus
Set menuLanguages }


MenuLanguage {

Menu menu
Language language
dsMenu -> Menu translation }

Language {

dsLanguage -> en_US for example
Set menuLanguages }



1) I need to load all menu child´s when i load a menu
Ok,i change lazy=true to false in menuChild set config.

2) I need to load all menus and it´s child by dsLanguage

select ml from MenuLanguage ml where ml.language.dsLanguageId = 'en_US' and ml.menu.parentMenu is null

It returns MenuLanguages, where i have a Menu and a Language.
For the father Menu there is no problem because i have the
dsMenu translation.
But for the child menu´s?

So i try to change the set menuLanguages to lazy=false.
Ok BUT, it returns all menuLanguages without condition.

But the translation for the child?
How could i solve that problem ?




http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1.7

Mapping documents:

Menu
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
>
<class
name="menu.Menu"
table="MENU"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>

<id
name="id"
column="cd_menu"
type="java.lang.Long"
>
<generator class="increment">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Menu.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<set
name="menuLanguage"
lazy="false"
inverse="true"
cascade="save-update"
sort="unsorted"
>

<key
column="cd_menu"
>
</key>

<one-to-many
class="menu.MenuLanguage"
/>

</set>

<set
name="childMenus"
lazy="false"
inverse="true"
cascade="save-update"
sort="unsorted"
>

<key
column="cd_menu_parent"
>
</key>

<one-to-many
class="menu.Menu"
/>

</set>

<many-to-one
name="parentMenu"
class="menu.Menu"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="cd_menu_parent"
/>

<property
name="cdUserRecord"
type="java.lang.Long"
update="true"
insert="true"
access="property"
column="cd_user_record"
not-null="true"
/>

<property
name="cdUserUpdate"
type="java.lang.Long"
update="true"
insert="true"
access="property"
column="cd_user_update"
not-null="true"
/>

<property
name="dsMenuId"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="ds_menu_id"
length="16"
not-null="true"
/>

<property
name="dtDeactivate"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="dt_deactivate"
/>

<property
name="dtRecord"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="dt_record"
/>

<property
name="dtUpdate"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="dt_update"
/>

<property
name="nrOrder"
type="int"
update="true"
insert="true"
access="property"
column="nr_order"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Menu.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>

MenuLanguage
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>


<class name="menu.MenuLanguage"
table="MENU_LANGUAGE"
lazy="true">

<composite-id name="id" class="menu.MenuLanguage$Id"
unsaved-value="any">

<key-property name="menuId"
column="cd_menu"/>

<key-property name="languageId"
column="cd_language"
/>
</composite-id>

<many-to-one name="menu"
insert="false"
update="false"
not-null="true"
column="cd_menu"/>

<many-to-one name="language"
insert="false"
update="false"
not-null="true"
column="cd_language"/>

<property
name="dsMenu"
update="true"
insert="true"
access="property"
column="ds_menu"
not-null="true"
/>

</class>

</hibernate-mapping>

Language
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
>
<class
name="menu.Language"
table="LANGUAGE"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>

<id
name="id"
column="cd_language"
type="java.lang.Long"
>
<generator class="increment">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Language.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<set
name="menuLanguage"
lazy="true"
inverse="true"
cascade="save-update"
sort="unsorted"
>

<key
column="cd_language"
>
</key>

<one-to-many
class="menu.MenuLanguage"
/>

</set>

<property
name="dsLanguage"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="ds_language"
length="16"
not-null="true"
/>

<property
name="dsLanguageId"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="ds_language_id"
length="5"
not-null="true"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Language.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>




Name and version of the database you are using:
Sybase

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 22, 2005 10:26 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
Up!


Top
 Profile  
 
 Post subject: Modeling problem?
PostPosted: Thu Apr 21, 2005 12:40 pm 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
I'd suggest making a composite ID for your objects, if you need to "filter" by language, it seems like you'd need the language ID to be part of your identifier.

Alternatively, you could look at your model and figure out whether language (by which it looks like you mean locale) is modeled properly. Do the menus truly have a different structure in different languages?


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