-->
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: Component null on load
PostPosted: Wed Mar 08, 2006 12:20 pm 
Contributor
Contributor

Joined: Sun Jun 26, 2005 5:03 am
Posts: 51
Location: London, UK
I have a very simple class containing a component


Code:
   public class Party : Entity
   {
      private Address address;
      private string telephone;
      private string email;

      #region Constructors
      public Party() : this(null)
      {
      }

      public Party(string name) : this(name, null)
      {
      }

      public Party(string name, string telephone) : this(name, telephone, null)
      {
      }

      public Party(string name, string telephone, string email) : base(name)
      {
         address = new Address();
         Telephone = telephone;
         Email = email;
      }
      #endregion

      /// <summary>
      /// Property Address (Address)
      /// </summary>
      public Address Address
      {
         get   { return address; }
         set { address = value; }
      }

      public string Telephone
      {
         get { return telephone; }
         set { telephone = value; }
      }

      public string Email
      {
         get { return email; }
         set { email = value; }
      }
   }


And I've mapped Address as a component


Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Lbth.Sar.Domain" assembly="Lbth.Sar.Domain" default-access="field.camelcase">
   <subclass name="Party" extends="Entity" discriminator-value="Party">
      <property name="Email" column="Email" type="String" />
      <property name="Telephone" column="Telephone" type="String" />
      <component name="Address" class="Address">
         <property name="Street" column="Street" type="String" />
         <property name="City" column="City" type="String" />
         <property name="Postcode" column="Postcode" type="String" />
         <property name="County" column="County" type="String" />
      </component>
   </subclass>
</hibernate-mapping>



Problem is, when I load Party that has an empty address, i.e. all the values of the component are null, then the Address reference is null as well.

I know I'm being thick somehow, but I haven't dealt with components for couple of months

_________________
Paul Hatcher
NHibernate Team


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 3:00 pm 
Contributor
Contributor

Joined: Sun Jun 26, 2005 5:03 am
Posts: 51
Location: London, UK
Ok, read some more of the Hibernate document - I think this is behaviour by design, since it treats a component as a value type internally.

So, if all the elements of the component are null, the component itself is null. I have a hack workaround for this which is to create a new Address object in Party automatically if the member variable is null

_________________
Paul Hatcher
NHibernate Team


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.