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: