-->
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: One-To-Many (FK Problem)
PostPosted: Tue Jan 05, 2010 12:27 pm 
Newbie

Joined: Tue Jan 05, 2010 12:15 pm
Posts: 9
I have two tables
Table A
ID int (PK)
ID2 int

Table B
ID int (PK)
A_ID int
A_ID2 int

I have created two classes one for table A named ClassA and one for table B named ClassB. A has a list with elements of B. Both ids of A are needed to find the entries in B.

classB.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="NHibernate4.ClassB, NHibernate4" table="B">
    <id name="ID" column="ID" type="int">
      <generator class="increment"/>
    </id>
  </class>
</hibernate-mapping>


classA.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="NHibernate4.ClassA, NHibernate4" table="A" lazy="false">
    <id name="ID" column="ID" type="int">
      <generator class="increment"/>
    </id>
    <property name="ID2" column="ID2" type="int"/>
    <set name="Bs" table="B">
      <key>
        <column name="ID"/>
        <column name="ID2"/>
      </key>
      <one-to-many class="NHibernate4.ClassB, NHibernate4"/>
    </set>
  </class>
</hibernate-mapping>


I get an exception during creating my factory
Foreign key (FKCDCAB7DE6C6BD79E:B [ID, ID2])) must have same number of columns as the referenced primary key (A [ID])

It is not a direct relation on the db side and i cann't change the db at the moment, it is the reason why i want to have hibernate so that i can start thinking about changing the db at all with all mapping in one place not scattered in dozens of files.

Any idea how i can get the list of Bs filled in A when i load one from the Db and stored as well?


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.