-->
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: self-reflexive n:m relation using composite keys
PostPosted: Sat Oct 16, 2010 8:05 am 
Newbie

Joined: Fri Oct 15, 2010 5:12 pm
Posts: 2
Hi,
I posted this on StackOverflow (http://stackoverflow.com/questions/3904100/self-reflexive-nm-relation-using-composite-keys-in-nhibernate), but got no answer....
I have a legacy database with 3 tables like this:
Image
The Items table contains all the Items in a Plan. The Structure table defines the relation between the items. A parent item is defined by company, year, planId and parentItem of table structure mapping to company, year, planId and id of table item.
A child item is defined by company, year, planId and childItem of table structure mapping to company, year, planId and id of table item.

I am searching for a way to do a n:m mapping in nhibernate using either hbm or fluent mappings.

I came up with:
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping namespace="Project.Model" assembly="Project" xmlns="urn:nhibernate-mapping-2.2">
  <class name="Item" lazy="true" table="`item`" schema="`dbo`">
    <composite-id>
        <key-property name="Company" column="`company`" />
        <key-property name="Year" column="`year`" />
        <key-property name="Planid" column="`planid`" />
        <key-property name="ItemId" column="`id`" />
    </composite-id> 
    <!-- Some other properties -->

    <set name="Parents" table="`structure`" fetch="select">
        <key>
            <column name="`company`" />
            <column name="`year`" />
            <column name="`planid`" />
            <column name="`parentItem`" />
        </key>
        <many-to-many class="Item">       
            <column name="`company`" />
            <column name="`year`" />
            <column name="`planid`" />
            <column name="`id`" />
        </many-to-many>
    </set>

    <set name="Childs" table="`structure`" fetch="select">
        <key>
            <column name="`company`" />
            <column name="`year`" />
            <column name="`planid`" />
            <column name="`childItem`" />
        </key>
        <many-to-many class="Item">       
            <column name="`company`" />
            <column name="`year`" />
            <column name="`planid`" />
            <column name="`id`" />
        </many-to-many>
    </set>

    <many-to-one name="Plan" class="Plan" not-null="true" fetch="select">
        <column name="`company`" />
        <column name="`planid`" />
    </many-to-one>
  </class>
</hibernate-mapping>


The error however is: Repeated column in mapping … - so I'm stuck. Any suggestions?


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.