-->
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.  [ 4 posts ] 
Author Message
 Post subject: How do I map a table when the primary key is a foreign key?
PostPosted: Thu Jun 07, 2007 4:06 pm 
Newbie

Joined: Wed Nov 29, 2006 6:53 pm
Posts: 7
Hello,

I used Hibernate tools to map a table from a legacy database. My problem is that the primary key (ao) is also a foreign key, and I don't know how to show this in the xml. This is what I have right now:

Code:
<hibernate-mapping>
    <class name="RepeatCallerAo" table="REPEAT_CALLER_AO" lazy="false">
        <id name="ao" type="string">
            <column name="AO" length="50" />
            <generator class="assigned" />
        </id>
        <many-to-one name="aoByRelatedAo2" class="Ao" fetch="select">
            <column name="RELATED_AO_2" length="50" />
        </many-to-one>
        <many-to-one name="aoByRelatedAo1" class="Ao" fetch="select">
            <column name="RELATED_AO_1" length="50" />
        </many-to-one>
        <property name="repeatLogicInd" type="string">
            <column name="REPEAT_LOGIC_IND" length="1" not-null="true" />
        </property>
    </class>
</hibernate-mapping>


the next two columns (aoByRelatedAo2 and aoByRelatedAo1) have the same relationship with the same table as the primary key and show a many to one relationship as expected. Is there a way to do the same with the primary key column?

Thanks in advance for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 5:55 pm 
Beginner
Beginner

Joined: Mon May 21, 2007 5:22 pm
Posts: 27
Location: Salt Lake City
[code]<generator class="foreign">
<param name="property">aoByRelatedAo2</param>
</generator>


<many-to-one name="aoByRelatedAo2" class="Ao" fetch="select">
<column name="RELATED_AO_2" length="50" />
</many-to-one> [/code]

_________________
Try 'N' Enjoy !!
Rahul

If helpful do rating ....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 7:27 pm 
Newbie

Joined: Wed Nov 29, 2006 6:53 pm
Posts: 7
Hi Rahul,

I don't understand what you mean in your reply. You're answer only referred to RELATED_AO_2, and thats not the one i'm having trouble with, I was asking about AO. Did you mean I should do something like this for AO?

Code:
        <id name="ao" type="string">
            <generator class="foreign">
               <param name="property">ao</param>
         </generator>
        </id>
        <many-to-one name="ao" class="com.att.ivr.drm.model.easl.v31.Ao" fetch="select">
            <column name="AO" length="50" />
        </many-to-one>



Thanks, I really appreciate any help!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 2:44 pm 
Beginner
Beginner

Joined: Mon May 21, 2007 5:22 pm
Posts: 27
Location: Salt Lake City
Yes correct.

you need to refer to the class name.

_________________
Try 'N' Enjoy !!
Rahul

If helpful do rating ....


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