-->
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.  [ 1 post ] 
Author Message
 Post subject: Relationship one-to-one an one-to-many
PostPosted: Tue Mar 13, 2012 11:51 am 
Newbie

Joined: Tue Mar 13, 2012 11:27 am
Posts: 1
I need to understand what relation should I have in case I have 3 tables.
The first has id and the 2 others has id to refer to the id in the first table.
All I found on the web is when having 2 tables – to use one-to-one relation. What is the relation in that case ?

For example, I have 3 tables:
Table 1- User-info:
Id
First Name
Last name

Table 2 – user-hobby:
User-Id (this should refer to column Id in table User-info)
Hobby
Table 3 – user-job:
User-Id (this should refer to column Id in table User-info)
Job


User-info.hbm.xml:
<id name="id" column="ID" unsaved-value="0">
<generator class="native" />
</id>

<property name="firstName" column="First_Name"/>
<property name=" lastName" column="Last_name"/>


user-hobby.hbm.xml
<id name="userId" column="ID">
<generator class="foreign">
<param name="property">id</param>
</generator>
</id>

<property name="hobby" column=" Hobby"/>
<one-to-one name="id" class="com.entity.UserInfo" constrained="true"/>

user-hobby.hbm.xml
<id name="userId" column="ID">
<generator class="foreign">
<param name="property">id</param>
</generator>
</id>

<property name="job" column=" Job"/>
<one-to-one name="id" class="com.entity.UserInfo" constrained="true"/>


Am I missing something here?
Should I declare something in User-info.hbm.xml ?

Thanking you in advance,
Eli


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.