-->
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: Inheritance mapping
PostPosted: Sat May 07, 2005 12:13 pm 
Newbie

Joined: Sat May 07, 2005 11:49 am
Posts: 4
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 9:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
The "best practice" way is to use HQL and "join fetching"; see the docs.

You could also enable join fetching in the mapping documents if you really wanted to. Although, note that if you went this route, it would be much more difficult to get a Meal without getting all of its associations.


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.