-->
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.  [ 11 posts ] 
Author Message
 Post subject: How to map <many-to-one> in a List?
PostPosted: Wed Jan 14, 2004 5:12 am 
Beginner
Beginner

Joined: Thu Sep 04, 2003 2:52 am
Posts: 29
I have a class like this:

Code:
class A {
  List nodes;
}


every node is an entity.

my mapping is like this:

Code:
<list name="nodes">
  <key column="a_index"/>
  <index column="posn"/>
  <many-to-one ...> // How to do here?
</list>


Thanks for any help!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 5:16 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
don't you mean one-to-many?
<one-to-many class="yourpackage.A" />
Justin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 5:19 am 
Beginner
Beginner

Joined: Thu Sep 04, 2003 2:52 am
Posts: 29
thanks for your help.

but I want to share every node ,if use <one-to-many> there would be many redundant data in the database.so I want to use many-to-one,so
some node could be re-referenced by A.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 5:30 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Hi,
I'm not quite sure if I understand your problem - what do you mean by redundant data?

If you are trying to share Nodes between A's where one Node can belong to many A's and an A can have any Node(s), aren't you after a many-to-many mapping?

i.e. Node *---------* A


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 5:37 am 
Beginner
Beginner

Joined: Thu Sep 04, 2003 2:52 am
Posts: 29
Thanks,I have got the key.I think <many-to-many> is the solution for my problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 6:10 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Have a look at http://www.xylax.net/hibernate/ it will clarify some stuffs

_________________
Emmanuel


Top
 Profile  
 
 Post subject: This is the most helpful hibernate document I have seen!
PostPosted: Tue Mar 23, 2004 9:23 pm 
Newbie

Joined: Tue Mar 23, 2004 7:19 pm
Posts: 3
Location: Pasadena, CA
emmanuel wrote:
Have a look at http://www.xylax.net/hibernate/ it will clarify some stuffs


Thanks Emmanuel!

_________________
They only babble who practise not reflection. -- Richard B. Sheridan


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 28, 2004 11:11 pm 
Newbie

Joined: Tue Mar 02, 2004 10:56 pm
Posts: 12
I have been searching for similar examples. What i would like to see is how to implement these collection combinations using different collection interfaces. Every example uses a Set.

I am missing two things; can someone answer this: the session.find/query intertfaces return List objects, but the most common collection interface used is the Set, I would like to use the List from bottom to top of the MVC, but have some difficulties understanding many-to-many implementations and composite indexes.

cord


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 29, 2004 7:25 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
A result list (ie a query result) is a List. It has no relation with <set, <bag, etc...

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 29, 2004 5:52 pm 
Newbie

Joined: Tue Mar 02, 2004 10:56 pm
Posts: 12
Thank you, then maybe i am missing something (no maybe about it).

Here is my typical process:
want to display nested list of objects, monkeys and their bananas on one page and then provide add/edit/delete features from there. Here is my model:

monkeymanager class
getmonkeys()
monkey class
getbananas()
bananas class

first, my monkeymanager.getmonkeys() calls session.query("FROM monkey as monkey"). this returns a java.util.List. Now, i would like to be able to present this data using struts logic:iterate (or jstl equiv).

3 questions
- given that i want to not have to rebuild Set instances with List data, i want to use the List all the way from my data bean, to my business layer, to my formaction, to my presentation - is that not the most common practice, or do people build Sets from Lists given their query results.
- is there a 'better' hibernate way to get my list of monkeys?
- i know it has something to do with lazy initialization, but i am not sure why my list of bananas is not populated. In my struts presentation i have the following:
<l:iterate id="monkey" name="monkeys">
<b:write name="monkey" property="name"/>
<l:present name="monkey" property=
<l:iterate id="banana" property="monkey.bananas">
<b:write name="banana" property="producer"/>
</l:iterate>
</l:present>
</l:iterate>

i get the list of monkey names iterated, but no information on bananas. I populate my monkeys collection using the Find method, does this not populate the child collections too? when does that happen and when could i force this to happen?

Thank you

Cord


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 9:33 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
from Monkey mon left outer join fetch mon.bananas

_________________
Emmanuel


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