-->
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.  [ 6 posts ] 
Author Message
 Post subject: Mapping Composite keys
PostPosted: Fri Nov 21, 2003 2:35 am 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
I would like an opinion and any pointers related to the following type of mapping. I realize the database structure is not ideal for hibernate. Unfortunately it cannot be changed at this time.

<class name="com.x.Region" table="region">
<id column="RGN" name="regionId" type="long">
<generator class="assigned" />
</id>
... Some properties
</class>

<class name="com.x.CustomerSales" table="customersales">
<composite-id>
<key-property column="RGN" name="regionId" type="long" />
<key-property column="CST" name="customerId" type="long" />
</composite-id>
... Some properties
<many-to-one name="region" column="RGN" not-null="true" class="com.x.Region" update="false" insert="false"/>
</class>

<class name="com.x.SalespersonSales" table="salespersonsales">
<id column="SLSPER" name="salespersonId" type="long">
<generator class="assigned" />
</id>
... Some properties
<many-to-one name="destination" class="com.x.CustomerSales">
<column name="RGN" />
<column name="CST" />
</many-to-one>
</class>

The names of these tables etc. are made up but reflect a situation I have run into several times recently. This seems to be working in my tests but I wonder if there is a better way to map these types of relationships.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 3:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Looks fine and stright forward to me. What are your concerns?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 11:25 am 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
Thanks for looking at this. I just haven't seen any examples of this type of composite mapping and wanted to get opinions. I have at least 20 tables out of 400 that have this type of mapping and don't want to go too far down the wrong path. The ugliest part of this mapping is the duplicate property mapping for RGN to regionId and region in the customersales table.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 11:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
oh you should map that <many-to-one> with insert="false" update="false".


you *could* use a <key-many-to-one> but I really don't recommend it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 12:08 pm 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
Thanks, for the input. I haven't ever used a <key-many-to-one> but I will look at it and try to understand when it is appropriate. The documentation on <key-many-to-one> is a little light so I will see how it works through testing. I will try to post something on this to the Wiki because I have to provide information on composite key mapping to our developers anyway.

The many-to-one does have update="false" insert="false" or did you mean in the salespersonsales file mapping to CustomerSales?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
ugh yeah sorry you are right i misread the second time


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