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.  [ 3 posts ] 
Author Message
 Post subject: Nhibernate Relationship Mapping
PostPosted: Sun Jan 21, 2007 5:04 pm 
Regular
Regular

Joined: Sun Jan 21, 2007 4:33 pm
Posts: 65
Hibernate version: 1.03

First off, let me say that I'm glad a friend of mine showed me NHibernate, it's a great tool, and I'm glad it's there.

Now, down to business, as it were.

I've read the examples that are available through Google and through this website regarding NHibernate. In particular, I've been paying close attention to mapping relationships in the .hbm.xml files. Here is a screenie of the relationships between my tables (done in Access, due to the nature of the application)


Image

So far, I've mapped the classes to the their tables in the DB, and the other tasks required, except for mapping the relationships.

In my reading of the documentation provided, I get the feeling that I should use the following code in the client.hbm.xml file:
Quote:
<SET name="Child" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-MANY class="SocksCDS.Child, SocksCDS" />
<SET name="Spouse" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-ONE class="SocksCDS.Spouse, SocksCDS" />
<SET name="Wages" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-ONE class="SocksCDS.Wages, SocksCDS" />
<SET name="Employer" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-MANY class="SocksCDS.Employer, SocksCDS" />
<SET name="Assistance" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-MANY class="SocksCDS.Assistance, SocksCDS" />


For each of the other .hbm.xml files (Employer, Child, Wages, Assistance) in each should be the following:
Quote:
<SET name="Client" cascade="all">
<KEY column="ClientID" />
<MANY-TO-ONE class="SocksCDS.Client, SocksCDS" />


Now, the second snippet of code bothers me, but in searching through the documentation, I'm not sure of what I'm looking for that will help. Every example I've read about on the internet always gives a simple (non realworld) example, or they give a simple realworld example that doesn't answer these questions)

My questions:

Is code Snippet #1 correct? (given the relationships expressed)

Do I need to also map these relationships in the other files, or once it's mapped in the client.hbm.xml, is it complete, since that is what is used to pull all of the other information?

Thanks again, and if there's any other resources you know of that answer these questions, please feel free to point me in that direction.

As a postscript: Does anyone know the correct Key column for the Access 2003 DB? I'm using 'identity' but am still writing code and haven't tested it yet, I wanted to ensure that the groundwork was done.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 4:04 pm 
Regular
Regular

Joined: Sun Jan 21, 2007 4:33 pm
Posts: 65
Having perused these forums since the initial creation of my post, I've noticed that there are at least 3 other users that are having similar problems. The documentation itself does not address the issues we are asking about in a direct manner, rather it presumes a level of Nhibernate competence that we do not yet possess. That is the reason that I come to the forums looking for direction. NHibernate is a neat tool, but part of that 'neat tool' is helping the users that use it.

If the issue I bring up is trivial in nature (which I'm almost sure of), then the answer should also be trivial. I'm not asking for someone to hold my hand, just for someone to either point me to documentation that addresses my issues, or to tell me how I've 'got it wrong', so that I can fix it and move on to code that I'm more comfortable with.


Top
 Profile  
 
 Post subject: Re: Nhibernate Relationship Mapping
PostPosted: Fri Jan 26, 2007 3:49 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Gortok wrote:
In my reading of the documentation provided, I get the feeling that I should use the following code in the client.hbm.xml file:
Quote:
<SET name="Child" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-MANY class="SocksCDS.Child, SocksCDS" />
<SET name="Spouse" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-ONE class="SocksCDS.Spouse, SocksCDS" />
<SET name="Wages" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-ONE class="SocksCDS.Wages, SocksCDS" />
<SET name="Employer" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-MANY class="SocksCDS.Employer, SocksCDS" />
<SET name="Assistance" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-MANY class="SocksCDS.Assistance, SocksCDS" />


For each of the other .hbm.xml files (Employer, Child, Wages, Assistance) in each should be the following:
Quote:
<SET name="Client" cascade="all">
<KEY column="ClientID" />
<MANY-TO-ONE class="SocksCDS.Client, SocksCDS" />


Now, the second snippet of code bothers me, but in searching through the documentation, I'm not sure of what I'm looking for that will help. Every example I've read about on the internet always gives a simple (non realworld) example, or they give a simple realworld example that doesn't answer these questions)

My questions:

Is code Snippet #1 correct? (given the relationships expressed)


The first snippet seems to be an invalid Xml: All </SET> closing tags are missing... And the tags should be in lowe case also, I belive..

Code:
<set name="Wages" cascade="all" lazy="true">
  <key column="ClientID" />
  <one-to-many class="SocksCDS.Wages, SocksCDS" />
</set>
should pre reprensitive (You have some <one-to-one instead of one-to-many>)

And in other mappings, You should have
Code:
<many-to-one name="Client" class="SocksCDS.Client, SocksCDS" column="ClientId" />


Gert

_________________
If a reply helps You, rate it!


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