-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem using custom PropertyAccessor
PostPosted: Thu Nov 10, 2005 5:33 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
I'm trying to implement a custom PropertyAccessor but I'm getting an 'Object reference not set to an instance of an object' exception:

Code:
[NullReferenceException: Object reference not set to an instance of an object.]
   NHibernate.Util.ReflectHelper.GetGetter(Type theClass, String propertyName, String propertyAccessorName) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Util\ReflectHelper.cs:102
   NHibernate.Util.ReflectHelper.ReflectedPropertyType(Type theClass, String name, String propertyAccess) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Util\ReflectHelper.cs:164
   NHibernate.Mapping.SimpleValue.SetTypeByReflection(Type propertyClass, String propertyName, String propertyAccess) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Mapping\SimpleValue.cs:155
   NHibernate.Cfg.Binder.BindRootClass(XmlNode node, RootClass model, Mappings mappings) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Cfg\Binder.cs:351
   NHibernate.Cfg.Binder.BindRoot(XmlDocument doc, Mappings model) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Cfg\Binder.cs:1536
   NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Cfg\Configuration.cs:228
   NHibernate.Cfg.Configuration.AddXmlReader(XmlTextReader hbmReader) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Cfg\Configuration.cs:542
   NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-1.0.0.0\src\NHibernate\Cfg\Configuration.cs:425


I've specified the custom accessor in my mapping file by setting the property access to my custom PropertyAccessor (which is derived from the BasicPropertyAccessor) using the fully qualified name of the class like so:

Code:
access="Framework.Core.CustomPropertyAccessor, Framework.Core"


It appears that when ReflectHelper.GetGetter is called the accessor returned from the PropertyAccessorFactory.PropertyAccessors[ propertyAccessorName ] (see below) returns null so when the attempt to get the getter in the following line throws the exception, which is not caught.


Code:
      public static IGetter GetGetter( System.Type theClass, string propertyName, string propertyAccessorName )
      {
         IPropertyAccessor accessor = null;

         try
         {
            // first try the named strategy since that will be the most likely strategy used.
            accessor = ( IPropertyAccessor ) PropertyAccessorFactory.PropertyAccessors[ propertyAccessorName ];
            return accessor.GetGetter( theClass, propertyName );
         }
         catch( PropertyNotFoundException )
         {
            // the basic named strategy did not work so try the rest of them
            foreach( DictionaryEntry de in PropertyAccessorFactory.PropertyAccessors )
            {
               try
               {
                  accessor = ( IPropertyAccessor ) de.Value;
                  return accessor.GetGetter( theClass, propertyName );
               }
               catch( PropertyNotFoundException )
               {
                  // ignore this exception because we want to try and move through
                  // the rest of the accessor strategies.
               }
            }
            throw;
         }
      }


Is this being caused because I've done something wrong in my mapping file when declaring the custom PropertyAccessor, or is this a bug?

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 6:57 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Looks like a bug to me, please report it in JIRA


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 7:34 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
Ah ha!

Just found the problem in an obscure post on the Hibernate forums (see: http://forum.hibernate.org/viewtopic.php?t=929081&highlight=propertyaccessor)...

If the type atribute isn't explicitly set on the property mapping then there will be problems; as soon as I set the type to match the property/field type of in the POCO class everything worked.

There's still an issue with how errors are reported, but the custom PropertyAccessor is now working.

Still wan't me to report it?

Cheers,

Symon.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.