-->
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.  [ 4 posts ] 
Author Message
 Post subject: nested list mapping
PostPosted: Tue Sep 08, 2009 10:15 am 
Newbie

Joined: Tue Sep 01, 2009 3:22 am
Posts: 5
Hi,

i have the following classes: MyClass, YourClass and HisClass

MyClass contains a List of YourClass
and
YourClass contains a List of HisClass

so I have a class (MyClass) that contains a List of Objects (YourClass), each of which contains a List of more Objects (HisClass)...

so I map:
Code:
<hibernate-mapping>
   <class name="MyClass" table="myclass">
      ...
      <property name="someproperty" />
      ...
      <list name="yourclass" table="myclass_yourclasses">
         <key column="myclass_id" />
         <list-index column="position" />
         <composite-element class="YourClass">
            ...
            <property name="someproperty" />
            ...
            <list name="hisclass" table="myclass_yourclasses_hisclasses">
               <key column="yourclass_id" />
               <list-index column="position" />
               <composite-element class="HisClass">
                  ...
               </composite-element>
            </list>
         </composite-element>
      </list>
   </class>
</hibernate-mapping>

but Hibernate would NOT let me use this mapping.
How would I do that?

Thanx for some hints.
Cheers
Björn


Top
 Profile  
 
 Post subject: Re: nested list mapping
PostPosted: Tue Sep 08, 2009 10:48 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Don't nest the List mappings, but instead, map the objects separately, each with its own contained list.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: nested list mapping
PostPosted: Tue Sep 08, 2009 12:23 pm 
Beginner
Beginner

Joined: Fri Jun 26, 2009 6:59 am
Posts: 23
From my own documentation, a piece of note.

The first issue to note when using One-to-Many is that Hibernate cannot fetch multiple ordered collections together, you’ll see the exception:
org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
In order to get around this, you need to define your Collection specifically as a Set, since Set is explicitly unordered, Hibernate can deal with as many multiple sets as you wish to use.


Top
 Profile  
 
 Post subject: Re: nested list mapping
PostPosted: Tue Sep 08, 2009 5:09 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Quote:
cannot simultaneously fetch multiple bags


I believe that if only one of the associated lists is eager, you can get around this. It's largely when there are multiple bags being eagerly loaded that you hit problems.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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