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.  [ 5 posts ] 
Author Message
 Post subject: Many to one on a join / intersect / relation table
PostPosted: Thu Aug 23, 2007 1:54 pm 
Beginner
Beginner

Joined: Wed Jul 11, 2007 7:21 pm
Posts: 21
Location: San Diego, CA
Okay, so let's say I have a Person and a Dog class.

- Person can have a Dog, but only one.
- Not all people have a Dog.
- Some Persons have the same Dog (person-> dog = many->one).

In my data schema, this is normalized properly as something like this:

create table Person
(PersonGuid uniqueidentifier not null primary key,
FirstName varchar(50) not null,
LastName varchar(50) not null)

create table Dog
(DogGuid uniqueidentifier not null primary key,
DogName varchar(50) not null)

create table PersonDog
(PersonGuid uniqueidentifier not null references Person(PersonGuid)
DogGuid uniqueidentifier not null references Dog(DogGuid)
)

--Slap a unique composite key on PersonGuid and DogGuid in PersonDog


I do not want to allowable nullable value into Person, with something like this:

(PersonGuid uniqueidentifier not null primary key,
FirstName varchar(50) not null,
LastName varchar(50) not null,
DogGuid uniqueidentifier null references Dog(DogGuid) )


Can anyone advise me on how i'm supposed to go about structuring that relationship? There doesn't seem to be a table attribute in the many->one relationship.

Thanks so much!


--------------------------------------------------------------------------

Hibernate version: urn:nhibernate-mapping-2.2

Mapping documents:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="MyAssembly.Person, MyAssembly" table="Internal.Person">
<id name="Guid" column="PersonGuid" type="Guid">
<generator class="guid"/>
</id>
<property name="FirstName" column="FirstName" type="String" length="50"/>
<property name="LastName" column="LastName" type="String" length="2"/>
</class>
</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="MyAssembly.Dog, MyAssembly" table="Internal.Dog">
<id name="Guid" column="DogGuid" type="Guid">
<generator class="guid"/>
</id>
<property name="Name" column="Name" type="String" length="50"/>
<property name="Legs" column="Legs" type="Int32" />
</class>
</hibernate-mapping>

Name and version of the database you are using:
MS SQL Server 2005 sp2

_________________
http://rebelheart.squarespace.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 29, 2007 4:12 pm 
Beginner
Beginner

Joined: Wed Jul 11, 2007 7:21 pm
Posts: 21
Location: San Diego, CA
Come on.. I google'd everywhere before I bothered you guys on the forums. I can't be the first person who is adhering to > 3rd normalized form and using NHibernate.

_________________
http://rebelheart.squarespace.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 30, 2007 4:59 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
I'm sorry to have to imform you that the 3rd normal form does not require relation tables for one-to-many relationships. Even if it were, I'd be hard pressed to find a better or more obvious candidate for denormalization.


Top
 Profile  
 
 Post subject: here
PostPosted: Thu Aug 30, 2007 9:48 pm 
Beginner
Beginner

Joined: Wed Aug 29, 2007 1:25 pm
Posts: 26
Location: Recife, PE, Brazil
hi mate,

you can find everything in this blog

http://sdesmedt.wordpress.com/?s=NHibernate

good luck!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 11, 2007 5:01 pm 
Beginner
Beginner

Joined: Wed Jul 11, 2007 7:21 pm
Posts: 21
Location: San Diego, CA
marcal wrote:
I'm sorry to have to imform you that the 3rd normal form does not require relation tables for one-to-many relationships. Even if it were, I'd be hard pressed to find a better or more obvious candidate for denormalization.


That's why I said "> 3rd normalized form". Additionally, I tend to denormalize for performance reasons, not to shoe horn my data model into the confines of a data access layer.

To the gentleman that posted the link, thank you very much! I'll be checking it out shortly!

_________________
http://rebelheart.squarespace.com


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