-->
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: one-to-many problem.
PostPosted: Sun Jun 27, 2010 9:23 am 
Newbie

Joined: Sun Jun 27, 2010 9:09 am
Posts: 1
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?


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.