-->
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: Foreign Key mapping in Hibernate
PostPosted: Thu Jul 06, 2006 3:14 am 
Beginner
Beginner

Joined: Fri Jun 16, 2006 7:47 am
Posts: 27
Hi,

I have a table A which has a foreign keys x,y which is constrained to a table B (whose Primary keys are x,y).

How do I do this with Hibernate?

Any help would be appreciated.

Thanks


Top
 Profile  
 
 Post subject: Re: Foreign Key mapping in Hibernate
PostPosted: Thu Jul 06, 2006 4:28 am 
Beginner
Beginner

Joined: Sat Nov 19, 2005 11:54 am
Posts: 22
An Example to read for your problem:

<?xml version='1.0' encoding='utf-8' standalone="no"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="Letter" table="LETTERS">
<id name="andicator" column="andicator">
<generator class="assigned"/>
</id>
<!-- foreign key decleration refrences to primary key in next class-->
<many-to-one
name="type_id"
column="type_id"
class="Letter_Type"
fetch="join"
access="property"
not-null="false"
not-found="ignore"
/>
</class>

</hibernate-mapping>

Primary key in other class:

<?xml version='1.0' encoding='utf-8' standalone="no"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="Letter_Type" table="Letter_Type">
<id name="type_id" column="TYPE_ID">
<generator class="assigned"/>
</id>
<property name="letter_type"/>

</class>


</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: Foreign Key mapping in Hibernate
PostPosted: Thu Jul 06, 2006 5:29 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
cooler8020002000 wrote:
I have a table A which has a foreign keys x,y which is constrained to a table B (whose Primary keys are x,y).


How did you map class A and class B ? You should have a look here. http://www.hibernate.org/hib_docs/v3/re ... ompositeid

If you define a composite id, it should be sufficient to reference directly property of other table.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 3:13 am 
Beginner
Beginner

Joined: Fri Jun 16, 2006 7:47 am
Posts: 27
Thanks saeed and batmat.
I have given credits to you both :)


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.