Hi all,
I new to NHibernate and I want to map a simple one to many aggregation.
I have a BannerCampaign ( extends from some abstract) that holds a list of banners.
My domain model:
BannerCampaign :
Code:
public class BannerCampaign: ACampaign
{
public virtual IList<Banner> BannerList { get; set; }
public BannerCampaign()
{
base.Type = CampaignType.BannerCampaign;
this.BannerList = new List<Banner>();
}
}
banners:
Code:
public class Banner
{
public virtual Int64 Id { get; set; }
public virtual Guid BannerUUID { get; set; }
public virtual ACampaign BannerCampaign { get; set; }
public Banner()
{
BannerUUID = Guid.NewGuid();
}
}
The BannerCampaign hbm:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly=""
namespace="">
<class name="ACampaign" table="campaign">
<id name="CampaignID" type="Int64" column="CampaignID">
<generator class="native"/>
</id>
...
<subclass name="BannerCampaign" discriminator-value="2">
<!-- Many-to-one mapping: banner -->
<bag name="BannerList" cascade="all-delete-orphan">
<key column="CampaignID" />
<one-to-many
class="xxx.BusinessObjects.Banner, xxx.BusinessObjects"/>
</bag>
</subclass>
</class>
</hibernate-mapping>
Banner hbm:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly=""
namespace="">
<class name="Banner" table="banner">
<id name="Id" type="Int64" column="id">
<generator class="native"/>
</id>
...
<!-- Many-to-one mapping: Campaign -->
<many-to-one name="BannerCampaign"
class="ACampaign"
column="CampaignID"
cascade="all" />
</class>
</hibernate-mapping>
In the data base I add a CampaignID column to the banner table.
when I save data I see the correct data is insert to Campaign table and banner table but
the CampaignID is not populated.
why??? I used to made this mapping a lot in hibernate in NHibernate something is different?