-->
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: many-to-one not using <id>
PostPosted: Fri Jul 21, 2006 1:28 am 
Newbie

Joined: Fri Jul 21, 2006 1:20 am
Posts: 1
Take this hypothetical situation. A Person has a collection of Courses. They join on person name (rubbish, i know, but hypothetical).

How would one go about creating a one to many relationship within person, using the PersonName as the joining field. Bearing in mind this is not my <id> field?

What I have below is as far as I have got, property-ref appears not to work in version 1.0.2, what is the recommendation?


Thank you very much,

Gary





nHibernate 1.0.2



Code:
This section is part of my Person class ->

      <set name="Courses" table="Course" inverse="false" lazy="true">
         <key column="PersonName" property-ref="Name"/>
         <one-to-many class="NHibTest.Course, NHibTestLib"/>
      </set>


..................................................................


<class name="NHibTestLib.Course, NHibtestLib" table="Course" lazy="true">
      <id name="Id" column="Id" type="Guid" length="32">
         <generator class="guid" />
      </id>

      <property name="PersonName" column="Person" insert="false" update="false"/>
      <property name="Name" column="Name" type="String" length="40"/>
   </class>









SQL Server 2005


Quote:
create table Course (
[Name] nvarchar(40),
Id uniqueidentifier,
[PersonName] nvarchar(40),
PRIMARY KEY (Id)
)

create table Person (
[Name] nvarchar(40),
Id uniqueidentifier,
pencil uniqueidentifier,
[domicile] nvarchar(40),
[currency] nvarchar(40),
[bigdata] nvarchar(40),
[age] int,
ptype char,
PRIMARY KEY (Id)
)
go



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.