-->
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: Mapping Many-To-Many problem
PostPosted: Mon May 14, 2007 10:33 am 
Newbie

Joined: Mon May 14, 2007 10:27 am
Posts: 2
I have a problem.
3 tables:
Company (CompanyId, Name)
Service (ServiceId, Name)
Company_Service (CompanyId, ServiceId, HourPrice)

How do map this relationship?

When the table Company_Service not have HourPrice column is easy. But the column HourPrice having me crazy.

Thanks in advanced.

Roberto.


Top
 Profile  
 
 Post subject: Re: Mapping Many-To-Many problem
PostPosted: Mon May 14, 2007 12:40 pm 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
ronunes wrote:
I have a problem.
3 tables:
Company (CompanyId, Name)
Service (ServiceId, Name)
Company_Service (CompanyId, ServiceId, HourPrice)

How do map this relationship?


The easiest way (not the only way) is to just make a third entity. So the Company may have a One-To-Many relationship with the CompanyService entity. You then could have a property and a Many-To-One relationship from CompanyService to Service.


Top
 Profile  
 
 Post subject: Re: Mapping Many-To-Many problem
PostPosted: Mon May 14, 2007 1:46 pm 
Newbie

Joined: Mon May 14, 2007 10:27 am
Posts: 2
jchapman wrote:
ronunes wrote:
I have a problem.
3 tables:
Company (CompanyId, Name)
Service (ServiceId, Name)
Company_Service (CompanyId, ServiceId, HourPrice)

How do map this relationship?


The easiest way (not the only way) is to just make a third entity. So the Company may have a One-To-Many relationship with the CompanyService entity. You then could have a property and a Many-To-One relationship from CompanyService to Service.


I solved...
<class name="Company,..." table="Company">
<id name="Id" type="Int32" unsaved-value="0">
<column name="CompanyId" sql-type="int" not-null="true" unique="true" index="PK_Company"/>
<generator class="native" />
</id>
<property name="Name" type="String">
<column name="Name" length="50" sql-type="varchar" not-null="false"/>
</property>
<bag name="CompanyServices" table="Company_Service" lazy="false">
<key column="CompanyId"/>
<composite-element class="CompanyService, ..." >
<property name="HourPrice" type="Decimal">
<column name="HourPrice" sql-type="real" not-null="false"/>
</property>
<many-to-one name="Service" column="ServiceId" />
</composite-element>
</bag>


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.