-->
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: help needed. Many-to-many. Losing relationship in DB
PostPosted: Wed Nov 01, 2006 1:03 pm 
Newbie

Joined: Tue Oct 31, 2006 2:34 pm
Posts: 7
i am trying to set up a many to many relation ship between "accounts" and "contacts".
My code is saving both the account and the contact object to the database, but it is not making an entry to the join table to maintain the relationship between the 2 objects. I've tried all the combinations of the "inverse" property that exist, as well as a number of other things. I'm at a loss as to why it is not saving the relationship between the two objects. Help is much appreciated.


Executing code
Code:
ISession session = factory.OpenSession();
         
Account newAccount = new Account();
newAccount.AccountName = accountName.Text;

Contact myContact = new Contact();
myContact.NameFirst = "John";
myContact.NameLast = "Smith";

newAccount.Contacts.Add(myContact);
   
session.SaveOrUpdate(newAccount);




Mappings
Code:
    <class name="portal.Account, portal" table="tblAccounts">
        <id name="AccountID" column="accountID" >
            <generator class="identity" />
        </id>
        <property name="AccountName" column="accountName" />
       
        <bag name="Contacts" table="tblContactAccountJoin" cascade="save-update"  inverse="false" lazy="false">
         <key column="accountID" />
         <many-to-many column="contactID" class="portal.Contact, portal"  />
        </bag>
    </class>

------------------------------------------------------------------------------


    <class name="portal.Contact, portal" table="tblContacts">
      <id name="ContactID" column="contactID" unsaved-value="0">
         <generator class="identity" />
      </id>      
      
      <bag name="Accounts" table="tblContactAccountJoin" cascade="save-update" inverse="false" lazy="false">
         <key column="contactID" />
         <many-to-many column="accountID" class="portal.Account, portal"  />
      </bag>
      
      <property name="NameFirst" column="nameLast" type="string" length="50" />
      <property name="NameLast" column="nameFirst" type="string" length="50" />
      
      <property name="Title" column="title" type="string" length="50" />
      
    </class>


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.