-->
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.  [ 2 posts ] 
Author Message
 Post subject: formula help
PostPosted: Sun Jan 29, 2006 11:53 am 
Newbie

Joined: Wed Aug 10, 2005 6:49 am
Posts: 10
Hibernate3.1:

I have Table A and Table B.

Fields in Table A
------------------
x - primary k
y - foreign key
z

fields in Table B
------------------
y - primary key
q
r

Tables A and B are joined by y and y.

In the mapping file I want to specify a one-ton-one where class B resides inside class A.

How do I specify how these tables are joined? The hibernate documentation says to use fomula when not mapping to the primary key of the owning entity however does not give an example of this case.


<class name="A" table="A" lazy="true">
<id name="id" column="x" type="long">
<generator class="foreign">
<param name="property">fieldProps</param>
</generator>
</id>
<property name="y" column="y" type="long"/>
<property name="z" column="z" type="long"/>

<one-to-one name="fieldProps" class="B" cascade="all"
formula="??????????????????????">
</one-to-one>
</class>

<class name="B" table="B" lazy="true">
<id name="id" column="y" type="long">
<generator class="increment" />
</id>
<property name="q" column="q" type="string"/>
<property name="r" column="r" type="string"/>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 29, 2006 3:17 pm 
Beginner
Beginner

Joined: Sun Jan 22, 2006 6:56 am
Posts: 29
If you look at it from the other way around you get the simple case. You're simply mapping the inverse side of a bidirectional one-to-one mapping.
What kind of model are you trying to achieve here? Is it a parent-child relationship? In this case you could say that B is the parent and A is the child (A can't live when B ceases to exist because of the foreign key). It doesn't matter that B is 'contained' in A. This is just a navigation link, and in this case the reference to B in A would be the inverse one.

I think when they talk about mapping to the primary key they mean mapping two tables by both's primary keys, rather than primary to foreign.


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