-->
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: private accessors and ExcludeProperty()
PostPosted: Fri Apr 28, 2006 10:50 am 
Beginner
Beginner

Joined: Tue Mar 28, 2006 3:44 am
Posts: 22
NHibernate version: 1.0.2


Hi @ll,

currently I'm struggeling with an interesting problem concerning private accessors explicitly generated for NHibernate.
My classes look like the following (an excerpt). All have generated public accessors with some plausibility checks and private accessors for NHibernate.
Code:
   public sealed class ItemDto:ICreated, IStatus, IModified
   {

      ...

      public string ItemDescription
      {
         get { return _item_description; }

         set   
         {   
            if(  value != null &&  value.Length > 100)
               throw new ArgumentOutOfRangeException("Invalid value for ItemDescription", value, value.ToString());
            
            _item_description = value;
         }
      }

      public DateTime DateCreated
      {
         get { return _date_created; }
         set
         {
            _date_created = value;
         }

      }
         
      public DateTime DateModified
      {
         get { return _date_modified; }
         set
         {
            _date_modified = value;
         }

      }

      ...

      private string _ITEM_DESCRIPTION
      {
         get { return _item_description; }
         set { _item_description = value; }
      }

      private DateTime _DATE_CREATED
      {
         get { return _date_created; }
         set { _date_created = value; }
      }

      
      private DateTime _DATE_MODIFIED
      {
         get { return _date_modified; }
         set { _date_modified = value; }
      }
      
      ...

}


To access NHibernate and all stuff concerning the database I implemented some sort of interface (in general terms) with a factory and generic stuff. To retrieve objects by an example I coded the following method.

Code:
        public List<T> GetByExample(T exampleInstance, params string[] exclude) {
            ICriteria criteria = session.CreateCriteria(persitentType);
            Example example = Example.Create(exampleInstance);
            example.ExcludeNulls();
            example.ExcludeZeroes();
           
            foreach (string propertyToExclude in exclude) {
                example.ExcludeProperty(propertyToExclude);
            }
           
            //example.ExcludeProperty("DateCreated");
            //example.ExcludeProperty("DateModified");
           
            example.ExcludeProperty("_DATE_CREATED");
            example.ExcludeProperty("_DATE_MODIFIED");
           
            example.EnableLike();

            criteria.Add(example);

            return ConvertToGenericList(criteria.List());
        }


As you can see two lines are marked as comments. Here is the "problem". If I use the public accessors to tell NHibernate which properties should be ignored it doesn't work. It only works if I use the private (NHibernate) accessors. So far it makes sense, but it's a problem with the array which provides dynamcally property names. The object that calls this method have to know the private accessors in order to exclude properties correctly. This violates some OO principles, so my question is whether there is an other possibility to choose the properties correctly without using the private accessors or not?

Many thanks in advance for your help.
Chavez


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.