-->
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.  [ 3 posts ] 
Author Message
 Post subject: Mapping a map with entities?
PostPosted: Mon Jan 26, 2004 9:20 am 
Newbie

Joined: Sun Jan 25, 2004 2:35 pm
Posts: 5
Hello,

I'am sorry I'am a newbie and I don't understand the docs how to map a map with entities. I have two classes Parent and Child:

Code:
public class Parent {

   private Map childs = new HashMap();
   private String name;

   public void setName(String name) {
   
      this.name = name;
   }

   public String getName() {

      return this.name;
   }

   public void setChilds(Map childs) {

      this.childs = childs;
   }

   public Map getChilds(Map childs) {
   
      return this.childs;
   }
}


public class Child {

   private String name;

   public void setName(String name) {
   
      this.name = name;
   }

   public String getName() {

      return this.name;
   }
}


... and the follwing table structure because of one child is able to have more than one parent:

Parents
=====
idParent | name

Parents_Childs
==========
idParent | idChild

Childs
====
idChild | name


The hashmaps of Parents should contain as key the name of the childs and as value the child objects.

My mapping doesn't work:

Code:
<class name="foo.bar.Parent" table="Parents">
      <id name="id" column="idParent">
         <generator class="increment"/>
      </id>
      <property  name="name"/>
      <map name="Childs" table="Parents_Childs">
         <key column="idParent"/>
         <many-to-many class="foo.bar.Child" column="idChild"/>
      </map>
   </class>

   <class name="foo.bar.Child" table="Child">
      <id name="id" column="idChild">
         <generator class="increment"/>
      </id>
      <property name="name"/>
   </class>


Thank you!

Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 12:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
For a starter, you are missing the index element of your map mapping. Please take a look at http://www.hibernate.org/hib_docs/reference/html/collections.html#collections-s1-5


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 12:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
And you should not use many-to-many but rather one-to-many for a parent child relationship.


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