-->
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 primary key with identity column and foreign key
PostPosted: Thu Jun 15, 2006 2:23 pm 
Newbie

Joined: Thu Jun 15, 2006 2:15 pm
Posts: 15
I need to map a table (AddressTable below) that uses an identity column and an integer column as the composit primary key. The integer column is a foreign key. Is there an example of how to map this?

ClientTable
CLIENT_KEY INTEGER <PK> IDENTITY


AddressTable
CLIENT_KEY INTEGER <PK FK> NOT NULL
ADDRESS_KEY INTEGER <PK> IDENTITY

This is what the tool generated but it doesn't work
<!-- Generated Jun 8, 2006 1:48:54 PM by Hibernate Tools 3.1.0.beta5 -->

<composite-id name="id" class="com.fbfs.claims.model.hibernate.LcltaddrId">
<key-property name="IClientKey" type="int">
<column name="I_CLIENT_KEY" />
</key-property>
<key-property name="IAddressKey" type="int">
<column name="I_ADDRESS_KEY" />
</key-property>
</composite-id>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 3:38 pm 
Newbie

Joined: Wed May 31, 2006 11:51 am
Posts: 3
We are doing something similar in our system. This is one of the few things I have working, but just to warn you it seems to break merge(). What you're doing is a bit different because you're using IDENTITY on your second column. I'm curious why this needs to be a composite id if you're using an IDENTITY? The IDENTITY should be the primary key. Then use a foreign key relationship.
Code:
Client:
      <one-to-one name="mailingAddress" class="Address" cascade="all" constrained="false" lazy="false" outer-join="false">
         <formula>client_id</formula>
         <formula>2</formula>
      </one-to-one>
Address:
      <composite-id unsaved-value="undefined">
         <key-many-to-one name="client"
               column="client_id"/>
         <key-property name="addressType"
               column="address_type_c"/>
      </composite-id>

_______
Todd V


Last edited by tmvander on Thu Jun 15, 2006 3:42 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 3:39 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Code:
<key-many-to-one
                    
           name="nameOfWhatever"
           class="package.name.NameOfWhatever"
           column="column" 
      
    >
    </key-many-to-one>

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 16, 2006 10:33 am 
Newbie

Joined: Thu Jun 15, 2006 2:15 pm
Posts: 15
[quote="tmvander"]We are doing something similar in our system. This is one of the few things I have working, but just to warn you it seems to break merge(). What you're doing is a bit different because you're using IDENTITY on your second column. I'm curious why this needs to be a composite id if you're using an IDENTITY? The IDENTITY should be the primary key. Then use a foreign key relationship.

Thanks for the response. Unfortunately I can't change the table design.
DBA (don't bother asking).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 16, 2006 4:22 pm 
Newbie

Joined: Thu Jun 15, 2006 2:15 pm
Posts: 15
The DBA agreed to change the table. I don't think there is a way to map this, and there doesn't need to be. Thanks for your help.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.