-->
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.  [ 2 posts ] 
Author Message
 Post subject: many-to-many without using primary keys
PostPosted: Tue Mar 20, 2007 3:22 pm 
Newbie

Joined: Fri Feb 25, 2005 10:59 am
Posts: 4
Hibernate version: 3

Hi,

I have a many to many association but i dont want to use the primary key on either object.

Can i do this?

I have a MediaPackGroup which contains a set of MediaPacks

The MediaPackGroup can have a category id and each MediaPack is also given a category.

If this doesnt make sense, i can explain more.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 12:39 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
many-to-many supports property-ref.

Assuming that there's a category table, which is your referential-intergrity table (but we'll pretend that it's a join table in this mapping):
Code:
<class name="MediaPackGroup" ...>
  ...
  <set name="Packs" table="Category" ...>
    <key column="categoryid"/>
    <many-to-many column="categoryid" class="MediaPack" property-ref="Groups"/>
  </set>
  ...
</class>

<class name="MediaPack" ...
  ...
  <set name="Groups" table="Category" ...>
    <key column="categoryid"/>
    <many-to-many column="categoryid" class="MediaPackGroup" property-ref="Packs"/>
  </set>
  ...
</class>

You don't need to map the category table if you don't want to. At least one of these tables needs an inverse="true" attribute: from your description, I'd say that both sides should be inverse (so that rows in the category table are never deleted).

I've never tried a mapping like this, where both the parent and child table use the same column in the join table, but I don't see any reason why it shouldn't be possible, if you set inverse="true" on both sides of the mapping.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.