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 relationship between tables with composite keys
PostPosted: Sat Jun 06, 2009 7:41 am 
Newbie

Joined: Sat Jun 06, 2009 6:53 am
Posts: 1
Hi!

I'm a newbie in nhibernate and in this forum and i don't know if this is the right place to post my question.
I'm sorry if this is not the place...


I have the following relation:

Table Entity_19 with the following columns Table Relationship_18 With columns Table Entity_20 with Columns

Attribute_78 dateTime pk Attribute_78 dateTime pk Attribute_83 float pk
Attribute_79 decimal pk Attribute_79 decimal pk Attribute_84 decimal pk
Attribute_80 float pk 1<--------- N Attribute_80 float pk N------->1 Attribute_85 dateTime pk
Attribute_81 float Attribute_83 float pk Attribute_86 char pk
Attribute_82 bit Attribute_84 dateTime pk Attribute_87 float pk
Attribute_85 decimal pk Attribute_88 tinyInt
Attribute_86 char pk
Attribute_87 float pk

Just to explain this a little better...
I have a many to many relation between table entity_19 and table entity_20, table relationship_18 is the relation Table.
How can i map this relation???

I have the following mapping files:


For entity_19:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="TheData" namespace="TheData.Domain">
<class name="TheData.Entity19" table="ENTITY_19" dynamic-insert="false" dynamic-update="false" select-before-update="false" polymorphism="implicit" optimistic-lock="version" lazy="false" >
<composite-id name="ID" class="TheData.Entity19+Entity19Key ">
<key-property type="System.DateTime" name="ATTRIBUTE78" column="ATTRIBUTE_78" />
<key-property type="System.Decimal" name="ATTRIBUTE79" column="ATTRIBUTE_79" />
<key-property type="System.Double" name="ATTRIBUTE80" column="ATTRIBUTE_80" />
</composite-id>
<property name="ATTRIBUTE81" column="ATTRIBUTE_81" type="System.Double" not-null="false" />
<property name="ATTRIBUTE82" column="ATTRIBUTE_82" type="System.Boolean" not-null="false" />
<bag name="ENTITY_19_ATTRIBUTE_78_RELATIONSHIP_18s" table="RELATIONSHIP_18" inverse="true" lazy="true" cascade="delete">
<key>
<column name="ATTRIBUTE_78" />
<column name="ATTRIBUTE_79" />
<column name="ATTRIBUTE_80" />
</key>
<one-to-many class="TheData.Relationship18" />
</bag>
<bag name="FK_RELATION_RELATIONS_ENTITY_11FK_RELATION_RELATIONS_ENTITY_2s" table="Relationship18" inverse="true">
<key>
<column name="ATTRIBUTE_78" />
<column name="ATTRIBUTE_79" />
<column name="ATTRIBUTE_80" />
</key>
<many-to-many class="TheData.Entity20" />
</bag>
</class>
</hibernate-mapping>


For entity_20:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="TheData" namespace="TheData.Domain">
<class name="TheData.Entity20" table="ENTITY_20" dynamic-insert="false" dynamic-update="false" select-before-update="false" polymorphism="implicit" optimistic-lock="version" lazy="false" >
<composite-id name="ID" class="TheData.Entity20+Entity20Key ">
<key-property type="System.Double" name="ATTRIBUTE83" column="ATTRIBUTE_83" />
<key-property type="System.Decimal" name="ATTRIBUTE84" column="ATTRIBUTE_84" />
<key-property type="System.DateTime" name="ATTRIBUTE85" column="ATTRIBUTE_85" />
<key-property type="System.String" name="ATTRIBUTE86" column="ATTRIBUTE_86" />
<key-property type="System.Single" name="ATTRIBUTE87" column="ATTRIBUTE_87" />
</composite-id>
<property name="ATTRIBUTE88" column="ATTRIBUTE_88" type="System.SByte" not-null="false" />
<bag name="ENTITY_20_ATTRIBUTE_83_RELATIONSHIP_18s" table="RELATIONSHIP_18" inverse="true" lazy="true" cascade="delete">
<key>
<column name="ATTRIBUTE_83" />
<column name="ATTRIBUTE_84" />
<column name="ATTRIBUTE_85" />
<column name="ATTRIBUTE_86" />
<column name="ATTRIBUTE_87" />
</key>
<one-to-many class="TheData.Relationship18" />
</bag>
<bag name="FK_RELATION_RELATIONS_ENTITY_11FK_RELATION_RELATIONS_ENTITY_2s" table="Relationship18" inverse="true">
<key>
<column name="ATTRIBUTE_83" />
<column name="ATTRIBUTE_84" />
<column name="ATTRIBUTE_85" />
<column name="ATTRIBUTE_86" />
<column name="ATTRIBUTE_87" />
</key>
<many-to-many class="TheData.Entity20">
</many-to-many>
</bag>
</class>
</hibernate-mapping>


For Relationship_18:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="TheData" namespace="TheData.Domain">
<class name="TheData.Relationship18" table="RELATIONSHIP_18" dynamic-insert="false" dynamic-update="false" select-before-update="false" polymorphism="implicit" optimistic-lock="version" lazy="false" >
<composite-id name="ID" class="TheData.Relationship18+Relationship18Key ">
<key-property type="System.DateTime" name="ATTRIBUTE78" column="ATTRIBUTE_78" />
<key-property type="System.Decimal" name="ATTRIBUTE79" column="ATTRIBUTE_79" />
<key-property type="System.Double" name="ATTRIBUTE80" column="ATTRIBUTE_80" />
<key-property type="System.Double" name="ATTRIBUTE83" column="ATTRIBUTE_83" />
<key-property type="System.Decimal" name="ATTRIBUTE84" column="ATTRIBUTE_84" />
<key-property type="System.DateTime" name="ATTRIBUTE85" column="ATTRIBUTE_85" />
<key-property type="System.String" name="ATTRIBUTE86" column="ATTRIBUTE_86" />
<key-property type="System.Single" name="ATTRIBUTE87" column="ATTRIBUTE_87" />
</composite-id>
<many-to-one name="RELATIONSHIP18_ATTRIBUTE78_ENTITY19Lookup" class="TheData.Entity19" update="0" insert="0" >
<column name="ATTRIBUTE_78"/>
<column name="ATTRIBUTE_79"/>
<column name="ATTRIBUTE_80"/>
</many-to-one>
<many-to-one name="RELATIONSHIP18_ATTRIBUTE83_ENTITY20Lookup" class="TheData.Entity20" update="0" insert="0" >
<column name="ATTRIBUTE_83"/>
<column name="ATTRIBUTE_84"/>
<column name="ATTRIBUTE_85"/>
<column name="ATTRIBUTE_86"/>
<column name="ATTRIBUTE_87"/>
</many-to-one>
</class>
</hibernate-mapping>


When i run this, i get the following error:

Foreign key (FKBB5AD8B15A43E0A1:Relationship18 [elt])) must have same number of columns as the referenced primary key (ENTITY_20 [ATTRIBUTE_83, ATTRIBUTE_84, ATTRIBUTE_85, ATTRIBUTE_86, ATTRIBUTE_87])



Can anyone help me please?

Thanks in advance,
Nilson


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.