Hi everybody!!!
Its the first time i use hibernate and i think its really working very well. But i have a little problem with inheritance mapping.
The structure of the hibernate mapping is that:
- we have one meal at the top
- a meal consists of many mealitems
- a meal item references a food object
- a food can be a single nourishment or a recipe
And the problem is, that whenever i want to output the complete meal (this means i iterator through the single mealitem, i access the food and output the name) hibernate always generates a single select for each food
isnt it possible that hibernate loads all foods when i load a meal from the database with ONE SINGLE select
here are some parts of the hiberante mapping...
the mapping of the meal class
Code:
<class name="Meal" table="MAHLZEITEN">
<id name="m_Id" column="ID" access="field">
<generator class="identity" />
</id>
<set name="m_MealItems" table="MAHLZEIT_BESTANDTEILE" access="field" cascade="save-update" fetch="join">
<key column="MAHLZEIT_ID"/>
<one-to-many class="easydiet.domain.mealplan.MealItemAmount"/>
</set>
</class>
the mapping of the mealitems Code:
<class name="MealItemAmount" table="MAHLZEIT_BESTANDTEILE">
<id name="m_Id" access="field" column="ID">
<generator class="identity"/>
</id>
<set name="m_Food" table="ESSEN" access="field" cascade="save-update">
<key column="ID"/>
<one-to-many class="easydiet.domain.food.Food"/>
</set>
</class>
the mapping of the food class Code:
<class name="Food" table="ESSEN">
<id name="m_Id" access="field" column="ID">
<generator class="identity"/>
</id>
<joined-subclass name="easydiet.domain.food.Nourishment" table="BLS_LEBENSMITTEL">
<key column="LEID"/>
....
.
....
</joined-subclass>
<joined-subclass name="easydiet.domain.food.Recipe" table="REZEPTE">
<key column="REID"/>
....
.
....
</joined-subclass>
</class>
and when i run the code in java, like i mentioned, hibernate makes a single sql query for every food object and doesnt load all once
thanks for every
greets
markus