-->
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: many-to-many mapping
PostPosted: Mon Jun 19, 2006 8:23 am 
Newbie

Joined: Mon Jun 19, 2006 7:47 am
Posts: 4
I have 3 tables
The first one:

PRODUCTS
-------------------
id
name
-------------------

The second one:
_____________
SPECIFICATIONS
---------------------------
id
name
dat
beg_dat
end_dat
____________

the link between them is many-to-many, but the "link table" must have not 2 fields(product_id,specification_id). It should have structure like this

LINKSPECPROD
----------------------------
ID*
----------------------------
spec_id
---------------------------
product_id
---------------------------
price
---------------------------

How can i do it?

ps

my mapping files are:
<class name="tables.Product" table="PRODUCTS">
<id name="id" column="PRODUCT_ID" type="long">
<generator class="native"/>
</id>
<property name="name" type="string" length="30" not-null="true" />
<set name="specifications" table="LinkSpecProd">
<key column="product_id"/>
<many-to-many class="tables.Specification">
<column name="spec_id"/>
</many-to-many>
<!--<many-to-many column="spec_id" class="tables.Specification/>-->
</set>
</class>

<class name="tables.Specification" table="SPECIFICATIONS">
<id name="id" column="ID" type="long">
<generator class="native"/>
</id>
<property name="name" type="string" length="30" not-null="true" />
<property name="dat" type="timestamp" not-null="true" />
<property name="beg_date" type="timestamp" not-null="false" />
<property name="end_date" type="timestamp" not-null="false" />
<set name="products" table="LinkSpecProd" inverse="true">
<key column="spec_id"/>
<!--<many-to-many column="product_id" class="tables.Product"/>-->
<many-to-many class="tables.Product">
<column name="product_id"/>
</many-to-many>
</set>
</class>

TIA, Constantine.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 10:41 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
Well, your link table is not a link table. It is a distinct entity. So you will need to create another class and mapping and make two many-to-one relationships between this new entity and the classes it relate; you should also have inverse one-to-many reference on the attribute(s) that would hold the many-to-many relationship.

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 4:37 am 
Newbie

Joined: Mon Jun 19, 2006 7:47 am
Posts: 4
thanks


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.