-->
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.  [ 10 posts ] 
Author Message
 Post subject: Foreign key in the mapping xml file
PostPosted: Wed Mar 24, 2004 8:42 am 
Newbie

Joined: Thu Feb 26, 2004 10:15 am
Posts: 7
Hi guys,
I have an object.
This object holds reference to another object.

I would like to set the foreign key of the containing object to
any field of the contained object.

How could be this done in the mapping xml file ?

The problem is that when Hibernate sets the foreign key of the containig object to the primary key of the contained object.

This is a sample of the mapping xml file I use.

<hibernate-mapping>

<class name="xxx.xx.ContainingObject" table="XXX">
<id name="id" column="id" type="long" unsaved-value="null">
<generator class="sequence">
<param name="sequence">XXX</param> <!-- nom de la sequence utilisee -->
</generator>
</id>
.
.
.
<set name="YYY" inverse="true" lazy="false" cascade="all-delete-orphan" where="clause where">
<key column="KEY TO BE SET"/>
<one-to-many class="xxx.xx.ContainedObject"/>
</set>

</hibernate-mapping>


What I want is th set the KEY TO BE SET value to a different field than
primary key of the contained object.

Any idea haw this could be done ?

Thank you.
moh.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 9:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use a property-ref.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 9:08 am 
Newbie

Joined: Thu Feb 26, 2004 10:15 am
Posts: 7
how?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 9:13 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
As described in the reference documentation.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 9:15 am 
Newbie

Joined: Thu Feb 26, 2004 10:15 am
Posts: 7
property-ref doesn't exist in
<one-to-many .....>
?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 9:18 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I don't see your problem, have you tried simply setting the <key> column to the column you want?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 9:33 am 
Newbie

Joined: Thu Feb 26, 2004 10:15 am
Posts: 7
example file maping
<hibernate-mapping>

<class name="A" table="A">
<id name="id" column="id" type="long" unsaved-value="null">
<generator class="sequence">
<param name="sequence">id</param> <!-- nom de la sequence utilisee -->
</generator>
</id>
<property name="b" column="B"/>
<property name="c" column="C"/>

<set name="listD" inverse="true" lazy="false" cascade="all-delete-orphan" >
<key column="d_code" />
<one-to-many class="D" />
</set>

</class>

the probleme may column d_code is refer to column c and not column id
of a ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 9:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is not possible. Use a query.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 10:03 am 
Newbie

Joined: Tue Feb 17, 2004 2:51 pm
Posts: 10
moh wrote:
example file maping
<hibernate-mapping>

<class name="A" table="A">
<id name="id" column="id" type="long" unsaved-value="null">
<generator class="sequence">
<param name="sequence">id</param> <!-- nom de la sequence utilisee -->
</generator>
</id>
<property name="b" column="B"/>
<property name="c" column="C"/>

<set name="listD" inverse="true" lazy="false" cascade="all-delete-orphan" >
<key column="d_code" />
<one-to-many class="D" />
</set>

</class>

the probleme may column d_code is refer to column c and not column id
of a ?


You might want to give this Jira Issue a vote:
http://opensource.atlassian.com/project ... key=HB-806

It's currently rejected, but who knows, if enough people ask for it something might happen. :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 12:32 pm 
Newbie

Joined: Thu Feb 26, 2004 10:15 am
Posts: 7
thanks with query its work


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