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: Help with inheritence
PostPosted: Wed Aug 30, 2006 1:39 pm 
Newbie

Joined: Tue Aug 22, 2006 4:01 pm
Posts: 2
I'm new at C# and nhibernate, so please bear with me. What I have is two tables (Awards and Conditions) with a many-to-many relationship. Conditions has a column called "Type" that I would like to use to determine the correct inherited class to instantiate for each record in the Conditions Table. DateConditon, RangeCondition, ValueCondition all inherit a base conditions class. Can anyone explain how this is set up or point me in the right direction? The relevant part of my hbm.xml is bellow.

Code:
  <class name="PromotionManager.Award, PromotionManager" table="Awards">
    <id name="Id" column="Id" type="int">
      <generator class="assigned" />
    </id>
    <property name="ShortName" column="ShortName" type="String" length="25"/>
    <property name="LongName" column="LongName" type="String" length="50"/>
    <property name="Description" column="Description" type="String" length="100"/>
    <property name="IsEnabled" column="IsEnabled" type="Boolean"/>
    <property name="ModifiedBy" column="ModifiedBy" type="int"/>
    <property name="ModifiedDate" column="ModifiedDate" type="DateTime"/>

    <bag name="Conditions" table="AwardsConditions"  inverse="true" cascade="all" outer-join="true">
      <key column="AwardId" />
      <many-to-many column="ConditionId" class="PromotionManager.Condition, PromotionManager"  />
    </bag>

  </class>

  <class name="PromotionManager.Condition, PromotionManager" table="Conditions">
    <id name="Id" column="Id" type="int">
      <generator class="assigned" />
    </id>
    <property name="ShortName" column="ShortName" type="String" length="25"/>
    <property name="LongName" column="LongName" type="String" length="50"/>
    <property name="Description" column="Description" type="String" length="100"/>
    <property name="Type" column="Type" type="String" length="10"/>
    <property name="Definition" column="Definition" type="StringClob" length="100"/>
    <property name="IsEnabled" column="IsEnabled" type="Boolean"/>
    <property name="ModifiedBy" column="ModifiedBy" type="int"/>
    <property name="ModifiedDate" column="ModifiedDate" type="DateTime"/>

    <bag name="Awards" table="AwardsConditions"  inverse="false" cascade="all" outer-join="true">
      <key column="ConditionId" />
      <many-to-many column="AwardId" class="PromotionManager.Award, PromotionManager"  />
    </bag>
   
  </class>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 2:25 pm 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Subclass sounds to be exaclty what You want http://www.hibernate.org/hib_docs/nhibernate/html/mapping.html#mapping-declaration-subclass

You will need to add <discriminator> element to the base class mapping

Gert

_________________
If a reply helps You, rate it!


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.