-->
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: NHibernate Mapping child to multiple parent
PostPosted: Wed Jun 15, 2011 5:38 am 
Newbie

Joined: Wed Jun 15, 2011 5:18 am
Posts: 2
Hi, first of all i'm quite new to NHibernate.

i have this problem with a legacy database.
first let see,

I have a table "Address" with the following fields:

Address
--------
id (pk)
ownertype (varchar)
ownerid (int)
addr1 (varchar)
add2 (varchar)
postcode (int)
...


and i might have other tables that has one-to-many relationship with the table above.
e.g: a table user might have multiple address related to its one row. and there might be another table that has same relationship. how to differentiate them is by putting discriminator value in the field "ownertype"

for now, i'm using mapping like below:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Entities" namespace="Entities">
  <class name="address" table="Address" where="STATUS != 'D'">
    <id name="ID" column="ADDID">
      <generator class="identity"/>
    </id>
    <any name="OWNER" id-type="System.Int32" meta-type="System.String">
      <meta-value class="user" value="enUser"/>
      <meta-value class="org" value="enOrg"/>
      <column name="OWNERTYPE" />
      <column name="OWNERID" />
    </any>
    <property name="ADDR1" />
    <property name="ADDR2" />
  </class>
</hibernate-mapping>


i can add entity "address" into entity "user" or "org" child just fine, and it works well in saving. but when i tried to access the address property, it give me error "The given key was not present in the dictionary"

Did I do the mapping correctly?
how do i solve this.

thanks for the help


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.