-->
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: Problem with unidirectional mapping
PostPosted: Mon Nov 17, 2008 10:53 am 
Newbie

Joined: Tue Nov 04, 2008 4:19 am
Posts: 3
I am using NHibernate 2.0.

I have a table with administrators and a table with phone numbers. I have a one-to-many relationship between these (i.e. an administrator can have many phone numbers).

This is represented in the domian model by the administrator having a PhoneNumberCollection of type ReadOnlyCollection<PhoneNumber>.

My mapping documents look like this:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="SecureDoxyLib" namespace="SecureDoxyLib.DomainLayer">
  <class name="Administrator" table="aspnet_Employees">
    <id name="UserId" column="UserId">
      <generator class="guid" />
    </id>

    <component name="Address" class="Address">
      <property name="Address1" type="String" column="Address1" not-null="true" />
      <property name="Address2" type="String" column="Address2" not-null="false" />     
      <property name="Country" type="String" column="Country" not-null="true" />
      <property name="FirstName" type="String" column="FirstName" not-null="true" />
      <property name="MiddleName" type="String" column="MiddleName" not-null="false" />
      <property name="LastName" type="String" column="LastName" not-null="true" />
      <property name="PostalCode" type="String" column="PostalCode" not-null="true" />
      <property name="City" type="String" column="City" not-null="true" />
      <property name="State" type="SecureDoxyLib.DomainLayer.USStateType, SecureDoxyLib" column="State" not-null="false" />
    </component>
   
    <set name="PhoneNumberCollection">
      <key column="UserId" />
      <one-to-many class="PhoneNumber"/>     
    </set>


  </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="SecureDoyxb" namespace="SecureDoxyLib.DomainLayer">

  <class name="PhoneNumber" table="aspnet_PhoneNumbers">
    <id name="PhoneId" column="PhoneId">
      <generator class="identity" />
    </id>
    <property name="Category" type="SecureDoxyLib.DomainLayer.PhoneCategoryType, SecureDoxyLib" column="PhoneCategory" not-null="true" />
    <property name="CountryCode" type="Int16" column="CountryCode" not-null="true" />
    <property name="Number" type="Int64" column="PhoneNumber" not-null="true" />
  </class>
</hibernate-mapping>


The problem is that all though the data is there in the table, the collection of phone numbers is always null on the administrator object. Does it have something to do with the type of collection on my domain object?


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.