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: Not able to do ONE-TO-ONE
PostPosted: Wed May 31, 2006 11:56 pm 
Beginner
Beginner

Joined: Mon May 22, 2006 12:12 am
Posts: 23
Hi,


Sorry, I've been struggling to clarify the terms. In my case below, I've 3 classes: LegalPerson, Address and Contact.

As a trial, I managed to get it done (i.e. have data records updated as expected) for the many-to-one relationship on LegalPerson-Address.

I was trying ONE-TO-ONE relationship for LegalPerson-Contact. (In the LegalPerson class,"contacts" is one of the properties) Schema generated the respective tables. However, the LegalPerson table DOES NOT have the expected field "contacts", which I would expect to update as the id for Contact class. How should I deal with ONE-TO-ONE relationship? Is it NECESSARY for me to add a "legalPerson" property inside Contact class to reference back to have the updat work?

thanks in advance. My LegalPerson.hbm.xml below:


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="RHU.RAIS.Business.LegalPerson, RHU.RAIS.Business" table="LegalPerson">
<id name="id">
<column name="id" not-null="true"/>
<generator class="native" />
</id>
<!-- A LegalPerson has to have a name, but it shouldn' be too long. -->
<property name="name">
<column name="name" length="255" not-null="true" />
</property>
<property name="legalPersonType">
<column name="legalPersonType" length="1"/>
</property>
<property name="legalId">
<column name="legalId" length="15"/>
</property>
<many-to-one name="addresses" class="RHU.RAIS.Business.Address, RHU.RAIS.Business" cascade="all" outer-join="true" column="addresses"></many-to-one>
<one-to-one name="contacts" class="RHU.RAIS.Business.Contact, RHU.RAIS.Business" cascade="all" outer-join="true"></one-to-one>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 4:57 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
If you have a field in the LegalPerson table for the contact, then it's not a one-to-one relationship, but a many-to-one. The database terminology is used here.


Top
 Profile  
 
 Post subject: confused
PostPosted: Thu Jun 01, 2006 5:05 am 
Beginner
Beginner

Joined: Mon May 22, 2006 12:12 am
Posts: 23
Excuse if I misunderstood:

Let set a Person has one Contact record only. Shouldn't it be one-to-one? Expect a reference field at the Person table to point to Contact record.

I interpreted that a many-to-one case would mean many Persons pointing to a single Contact record.

Sorry, need clarifications here.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 8:02 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
As I said, it's standard terminology so if you Google for database relationship types, you should find plenty of explanations. For example, this one: http://www.onlamp.com/pub/a/onlamp/2001/03/20/aboutSQL.html.

In short, if there's a reference field in Person table to point to Contact record, nothing prevents many persons pointing to a single Contact record and that's why it's called many-to-one.


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.