-->
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.  [ 1 post ] 
Author Message
 Post subject: Many-to-many self relation
PostPosted: Thu Jul 21, 2011 4:12 pm 
Newbie

Joined: Thu Jul 21, 2011 3:58 pm
Posts: 1
Hello everybody, i'm new with this and i wanted to do an example where a Person has many Friends. So I think is a many-to-many relation. So i made this mapping:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Domain" namespace="Domain">

  <class name="Person" table="Person">
    <id name="ID" column ="id" type="int" unsaved-value="0">
      <generator class="native"/>
    </id>
    <property name="Name" type="String" column="nombre" not-null="true" length="100"/>
    <property name="LastName" type="String" column="apellido" not-null="true" length="100"/>
    <property name="Address" type="String" column="direccion" not-null="true" length="200"/>
    <property name="Age" type="String" column="edad" not-null="true" length="3"/>
    <bag name="Friendships" table="Friendship">
      <key column="me_id"/>
      <many-to-many column="friend_id"
         class="Person"/>
    </bag>
  </class>
</hibernate-mapping>


And the class definition is the following:
Code:
  public class Person
    {
        public virtual String Name { get; set; }
        public virtual String LastName { get; set;}
        public virtual String Age {get; set;}
        public virtual String Address {get;set;}
        public virtual int ID { get; set; }
        public virtual IList<Persona> Friendships { get; set; }

        public Person()
        {

        }
    }


The problem is that, when i call the method session.Save(person) . The person is inserted but in the table "Friendship" there is no data inserted. May be problem that the "Friends" are already in the "Person" table? Does anybody has an idea of why the middle table (Friendship) is not saving any data?

Thank you


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.