-->
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.  [ 5 posts ] 
Author Message
 Post subject: Composite key mapping
PostPosted: Thu Feb 19, 2009 8:06 pm 
Newbie

Joined: Thu Feb 05, 2009 4:17 pm
Posts: 8
Hibernate 3

Hi, I'm trying to do the mapping for the following relationship:

CartTable
- ID (PK)
- HeatKitModel
- ProductID
HeatKitModel is foreign key to HeatKitTable.ItemNumber

ProductTable
- ID (PK)
- HeatKitTableName
HeatKitTableName is foreign key to HeatKitTable

HeatKitTable
- TableName
- ItemNumber
(TableName & ItemNumber are composite key for HKTable)

In my Cart class, I want to have a reference to the HK Object.
I was trying to do many-to-one mapping to the HeatKit Table, but I was unable to, since in CartTable, I only have one part of the composite key (HeatKitModel). The other part is in ProductTable (but I have ProductID and I could resolve it).
Could you please give me a suggestion on how I should map these?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2009 7:07 am 
Beginner
Beginner

Joined: Thu Feb 19, 2009 5:48 am
Posts: 37
Location: Glasgow, Scotland
Are you just talking about mapping a composite key in your mapping file? like this?...

Code:
<class name="HeatKitTable" table="HEATKIT"> 
  <composite-id>
    <key-property name="tableName"/>
    <key-property name="itemNumber"/>
  </composite-id>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2009 11:54 am 
Newbie

Joined: Thu Feb 05, 2009 4:17 pm
Posts: 8
Thank you for your reply.
Yes, I have done that.
But now I'm trying to make cart to have a HeatKit.
The relationship is many to one.

Code:
<many-to-one name="heatKit"
   class="com.mycompany.HeatKit"
   insert="false" update="false" not-null="true"
   fetch="join" lazy="false"> 
   <column name="HEATKITMODEL"/>
</many-to-one>

This mapping will complain that it's missing another key since HeatKit has composite key.

I was trying to put use the other foreign key, which is TableName, but cart doesnt have it. It needs to get it from ProductTable. Is it possible to do this in the mapping?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2009 12:03 pm 
Beginner
Beginner

Joined: Thu Feb 19, 2009 5:48 am
Posts: 37
Location: Glasgow, Scotland
Why not just have a one-to-many FROM the HeatKit to the Kart..

Code:
<one-to-many name="kart" class="kart" />


Then the foreign key from the Kart is stored in all instances of HeatKit that reference it? Rather than having an intermediate table?

_________________
##############################
If I helped, rate my comment, I have plenty of stupid questions to ask that I need credit for ;)
##############################


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2009 12:08 pm 
Newbie

Joined: Thu Feb 05, 2009 4:17 pm
Posts: 8
Well, logically, I would want to get which HeatKit is for this Cart, not which Cart contains this HeatKit.
My use case would always start from Cart.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.