Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NHibernate NullReferenceException for null value types in entities #2671

Closed
ZhaoRd opened this issue Nov 12, 2017 · 2 comments
Closed

NHibernate NullReferenceException for null value types in entities #2671

ZhaoRd opened this issue Nov 12, 2017 · 2 comments
Assignees
Milestone

Comments

@ZhaoRd
Copy link
Contributor

ZhaoRd commented Nov 12, 2017

Github Issues

  • Abp version : 1.5.2
  • Your base framework: .Net Framework 4.5.2.
  • Exception message and stack trace .
*****Error***** 
 NHibernate.Exceptions.GenericADOException: System.NullReferenceException: The object reference is not set to an instance of the object。
   in Abp.NHibernate.AbpNHibernateInterceptor.NormalizeDateTimePropertiesForComponentType(Object componentObject, IType type)
   in Abp.NHibernate.AbpNHibernateInterceptor.NormalizeDateTimePropertiesForEntity(Object[] state, IList`1 types)
   in Abp.NHibernate.AbpNHibernateInterceptor.OnLoad(Object entity, Object id, Object[] state, String[] propertyNames, IType[] types)
   in NHibernate.Event.Default.DefaultPreLoadEventListener.OnPreLoad(PreLoadEvent event)
   in NHibernate.Engine.TwoPhaseLoad.InitializeEntity(Object entity, Boolean readOnly, ISessionImplementor session, PreLoadEvent preLoadEvent, PostLoadEvent postLoadEvent)
  
  • Steps needed to reproduce the problem.

Stack Overflow

  • Add ValueObject like code
 public class TimeRange : ValueObject<TimeRange>
    {
        public DateTime? Start { get; set; }

        public DateTime? End { get; set; }
    }
  • Add Entity
public class BreakScheduleTime : EntityBase
    {
        public BreakScheduleTime()
        {
            this.TimeRange = new TimeRange();
        }

        /// <summary>
        /// 休息时间范围
        /// </summary>
        public virtual TimeRange TimeRange { get; set; }
}

My Code like up,when I save BreakScheduleTime .TimeRange all Start and End null , it can be saved.
But when I get BreakScheduleTime , it's error , error message is 'System.NullReferenceException: The object reference is not set to an instance of the object'.
If one of start and end is not null , get BreakScheduleTime is ok .
I look at the abp source code.
code file AbpNHibernateInterceptor.cs, the 226 row, I think must guard the componentObject is not null, so I change this code like

private static void NormalizeDateTimePropertiesForComponentType(object componentObject, IType type)
        {
            if(componentObject == null)
           {
               return ;
           }
            var componentType = type as ComponentType;
...
}

I use up code is ok , so I think the code in AbpNHibernateInterceptor.cs has a bug.

Am I right ?

@hikalkan hikalkan added this to the v3.2 milestone Nov 12, 2017
@hikalkan
Copy link
Member

It can be a bug. We will work on that. Thank you for reporting.

@ismcagdas
Copy link
Member

@ZhaoRd can you also share your mapping for BreakScheduleTime entity ?

@hikalkan hikalkan changed the title AbpNHibernateInterceptor bug : System.NullReferenceException NHibernate NullReferenceException for null value types in entities Nov 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants