-->
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: Relationship problem?
PostPosted: Tue Sep 20, 2005 3:34 am 
1. Does NHibernate support parent/child relationship via multiple fields? Example: Table1.Field1 + Table1.Field2 matches Table2.Field1 + Table2.Field2.
2. I


Top
  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 1:58 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
1. Yes it does, using <composite-id>.
2. It doesn't use a join because you probably didn't tell it to. Use outer-join="true" in the mappings, or a HQL query with 'left join fetch'.


Top
 Profile  
 
 Post subject: Relationship problem?
PostPosted: Wed Sep 21, 2005 5:39 am 
1. Yes it does, using <composite-id>.

Quote:
I've 2 tables:

Table1
{
ID (PK) int
ActorTypeID int
}

Table2
{
ID (PK) int
ActorTypeID int
ActorID int
}

Relations :
1. Table1.ID<-->Table2.ActorID
2. Table1.ActorTypeID<-->Table2.ActorTypeID.


Help me with writing map file for them, please.

2. Also I've another one question: does NHibernate support next relationship - One object


Top
  
 
 Post subject: Relationship problem?
PostPosted: Wed Sep 21, 2005 6:51 am 
Quote:
I've 2 tables:

Table1
{
ID (PK) int
ActorTypeID int
}

Table2
{
ID (PK) int
ActorTypeID int
ActorID int
}

Relations :
1. Table1.ID<-->Table2.ActorID
2. Table1.ActorTypeID<-->Table2.ActorTypeID


I forgot to say that I have another one table:
Quote:
Table3
{
ID (PK) int
EmployeeID int
}

Relations:
1. Table3.EmployeeID<-->Table1.ID


And if I use <composite-id> for Table1:
Quote:
<composite-id>
<key-property name="Id" column="ID"/>
<key-property name="ActorTypeID" column="ActorTypeID"/>
</composite-id>


Then for Table3 I need to define relation on 2 columns - but I've relation only on one column - How to corect write a map file for this scheme?


Top
  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 6:05 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
From my experience it is easier to work with NHibernate when the database is normalised. This also means that you should use a surrogate primary key (an autoincremented primary key instead of the composite primary key - it makes your life easier. As a consequence your foreign key will be simpler too!

I'm not a database design expert but a FK-FK relationship is not modeling anything. There are 3 type of associations:
1. one-to-one which is modeled with PK-FK or PK-PK
2. one-to-many which is modeled with PK-FK
3 many-to-many which is simplified to two one-to-many by creating a joining table.

O/R mappers are designed to work with this kinds of relationships.

When in my work I encountered FK-FK relationships it was because of poor database design and I transformed them to PK-FK by mapping to a view built specifically to correct that anomaly.

Regards,
Radu


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.