Wednesday, June 21, 2006

NHibernate debugging Could not save object

NHibernate.Util.ADOExceptionReporter [(null)] <(null)> - Could not save NHibernate.Util.ADOExceptionReporter [(null)] <(null)> - Could not save objectSystem.NullReferenceException: Object reference not set to an instance of an object. at NHibernate.Property.BasicSetter.Set(Object target, Object value) at NHibernate.Persister.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values) at NHibernate.Impl.SessionImpl.DoSave(Object theObj, Key key, IClassPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IClassPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)2006-06-21 21:15:41,187 [5260] WARN NHibernate.Util.ADOExceptionReporter [(null)] <(null)> - System.NullReferenceException: Object reference not set to an instance of an object. at NHibernate.Property.BasicSetter.Set(Object target, Object value) at NHibernate.Persister.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values) at NHibernate.Impl.SessionImpl.DoSave(Object theObj, Key key, IClassPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IClassPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)

The reason is that one of the mapping property does not have a setter, it only has a getter.
This is a hard one to find because normally Nhibernate will tell you that it cannot find the setter of the property, however, instead, it throws a null reference error.
The way with which I found this is to comment out some part of the mapping file and see if the error still occurs when this part of the mapping file is comment out. So I can locate which mapping property is causing the error.