-->
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.  [ 2 posts ] 
Author Message
 Post subject: Class Association mapping question
PostPosted: Wed Nov 05, 2008 12:58 pm 
Regular
Regular

Joined: Tue Feb 07, 2006 4:27 pm
Posts: 69
Hi,

I have 2 associated classes. Each has a legacy composite-key
where the fields are different from each other...
(this is a db that we have no control over :( )...

I thought the way would be to use property-ref for the many-to-one
and one-to-one mappings and possibly use a component to create the property of the foreign key for
MarketerSegment - MarketerSegmentContact

I'm getting the following error:

Code:
NHibernate.MappingException: property mapping has wrong number of columns:


Am I even close?

MarketerSegment - MarketerSegmentContact

Marketer Key
[TagIndex]
[TagMSIndex]

MarketerSegmentContact Key
[TagIndex]
[TagContactIndex]


MarketerSegment FK to MarketerSegmentContact

[TagIndex]
[ContactIndex]

MarketerSegment key:
Code:
    <composite-id name="Id" class="CommonSegmentKey">
      <key-property name="TagIndex" column="TagIndex"/>
      <key-property name="Sequence" column="TagMSIndex"/>
    </composite-id>


MarketerComponentMapping:
Code:
   
  <component name="ContactKey" 
                     class="Domain.ContactInformationKey, Domain">
      <property name="TagIndex" column="TagIndex" />
      <property name="Sequence" column="ContactIndex"/>
    </component>


MarketerContact Key:
Code:
    <composite-id name="Id" class="ContactInformationKey">
      <key-property name="TagIndex" column="TagIndex"/>
      <key-property name="Sequence" column="TagContactIndex"/>
    </composite-id>


I'm trying to map the relationship in each file and I am not getting very far...

MarketerSegmentContact mapping:
Code:
    <many-to-one name="MarketerSegment" class="MarketerSegment"
           property-ref="ContactKey"/>


MarketerSegment mapping to MarketerSegmentContact

Code:
<one-to-one name="Contact" class="MarketerSegmentContact" property-ref="MarketerSegment" />


Top
 Profile  
 
 Post subject: Fix to this issue
PostPosted: Wed Nov 05, 2008 1:42 pm 
Newbie

Joined: Wed Nov 05, 2008 1:08 pm
Posts: 1
Ok. I was able to get it working... I had the many-to-one - one-to-one backwards...

Here is what the mappings look like:


MarketerSegment:
Code:
   
    <many-to-one name="Contact"
             class="MarketerSegmentContact" not-found="ignore">
      <column name="TagIndex"/>
      <column name="ContactIndex"/>
    </many-to-one>


MarketerSegmentContact
Code:
<one-to-one name="MarketerSegment"
        property-ref="Contact" class="MarketerSegment"/>


The many-to-one mapping identifies the columns that make up the
composite id of the associated row in the contact table.

The one-to-one mapping make use of the property of the associated
class that is mapped using the many-to-one mapping..

Greg


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