-->
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: Foreign key mapping
PostPosted: Tue Sep 13, 2005 5:27 am 
Newbie

Joined: Tue Sep 13, 2005 5:17 am
Posts: 3
I have two tables:

Table1

* Pk1 (integer)
* Pk2 (integer)
* Pk3 (integer)
fk1 (integer)


and

Table2

*fk1 (integer)
*Pk5 (integer)
desc

I would map with xml descriptors the relation between table1 and table2 using fk1. Anny suggestions?

Thanks in advance for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 7:34 am 
Beginner
Beginner

Joined: Mon Apr 12, 2004 6:33 pm
Posts: 35
In hibernate you do not map foreign keys. In object terms there is no such thing as a foreign key.

In OR-land you map an object and its associations to other objects. I suggest you read this chapter: http://www.hibernate.org/hib_docs/v3/re ... pping.html

_________________
Kees de Kooter

(don't hesitate to rate ;)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 10:12 am 
Newbie

Joined: Tue Sep 13, 2005 5:17 am
Posts: 3
I donĀ“t understand what you want to say exactly...

I only need to obtain the xml that corresponds to my tables definition. I know how I can relation two tables with compound keys but not in this case.

In this example, one element of foreign key fk1 in table1 correspond to many elements on table2.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 11:38 am 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
elCarboner wrote:
In this example, one element of foreign key fk1 in table1 correspond to many elements on table2.

Looks like a nasty one to me. One question to clarify my thoughts:
is fk1 a unique index in Table1 or is there actually a many to many relationship between Table1 and Table2 over fk1?

Erik


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 12:26 pm 
Newbie

Joined: Tue Sep 13, 2005 5:17 am
Posts: 3
fk1 is a unique index on table1.

I know that is not the best form to relation this tables, but my legacy system is so fussy...

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 1:11 pm 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
I would recommend something like
Code:
<class name="Table2 ...>
  <composite-id>
    <key-property name="fk1" />
    <key-property name="pk5" />
  </composite-id>
  <many-to-one class="Table1" name="table1" property-ref="fk1" column="fk1" insert="false" update="false" />
</class>

<class name="Table1">
  <...>
  <property name="fk1" unique="true" not-null="true" />
  <set name="table2s" >
    <key>
      <column name="fk1" />
    </key>
    <one-to-many class="Table1"/>
  </set>
</class>


Note that this is only the draft of a draft...
Hope this helps anyway

Erik


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.