-->
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: Collection many-to-many between same table
PostPosted: Mon Oct 10, 2005 2:48 pm 
Beginner
Beginner

Joined: Sun Oct 09, 2005 3:21 pm
Posts: 40
Want to create a relation object (many-to-many) between records from the same table...

Say I have a table called RESOURCE (with ID, type, and name columns) and want to describe relationships between resources in a relational object. For example,

RELRESOURCE (table)
-------------------------
RESOURCEID1, id: long
RESOURCEID2, id: long

where RESOURCEID1 and RESOURCEID2 have foreign key constaints to an identity column in the RESOURCE table.

How do I represent this in the mapping document for the RESOURCE table? Assuming with the set element.


/ Matthew


Top
 Profile  
 
 Post subject: Additional information
PostPosted: Mon Oct 10, 2005 3:49 pm 
Beginner
Beginner

Joined: Sun Oct 09, 2005 3:21 pm
Posts: 40
have tried:

Code:
<set name="relResources" table="RELRESOURCE">
                <key column="RESOURCEID1"
                        not-null="true"
                        foreign-key="mykey2"/>
                <many-to-many column="RESOURCEID2"
                        class="Resouce"
                        foreign-key="mykey3"/>
</set>


which generates decent looking alter statement but still missing a mapping between the RESOURCEID2 column in the RELRESOURCE table and the RESOURCEID column of the RESOURCE table (see result below from SchemaExportTask):

Code:
alter table RELRESOURCE
  add constraint mykey2 foreign key (RELRESOURCEID1)
  references RESOURCE;

alter table RELRESOURCE
  add constraint mykey3 foreign key (RELRESOURCEID2)
  references RESOURCE;


instead i want:

Code:
alter table RELRESOURCE
  add constraint mykey2 foreign key (RELRESOURCEID1)
  references RESOURCE (RESOURCEID);

alter table RELRESOURCE
  add constraint mykey3 foreign key (RELRESOURCEID2)
  references RESOURCE (RESOURCEID);
[/code]


Top
 Profile  
 
 Post subject: Collection many-to-many between same table
PostPosted: Wed Oct 19, 2005 3:48 pm 
Newbie

Joined: Wed Oct 19, 2005 3:45 pm
Posts: 14
I am trying to do the same association many to many between the same table but i donĀ“t know how to implement it..
Could u find a solution for this issue ???


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.