-->
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.  [ 4 posts ] 
Author Message
 Post subject: NullReferenceException in NormalizedEntityPersister.Update
PostPosted: Fri Jan 20, 2006 4:09 pm 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Hibernate version:
1.0.2.0

Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<hibernate-mapping default-access="field.pascalcase-m-underscore" xmlns="urn:nhibernate-mapping-2.0">
  <class name="NHibernate.Bugs.Base, NHibernate.Bugs" table="Base" proxy="NHibernate.Bugs.Base, NHibernate.Bugs">
    <id name="ObjectId" type="Int32" unsaved-value="-1">
      <generator class="native" />
    </id>
    <version column="VersionCounter" name="VersionCounter" type="Int32" />
  </class>
  <joined-subclass name="NHibernate.Bugs.Parent, NHibernate.Bugs" table="Parent" proxy="NHibernate.Bugs.Parent, NHibernate.Bugs" extends="NHibernate.Bugs.Base, NHibernate.Bugs">
    <key column="ObjectId" />
    <set name="Childs" lazy="true" inverse="true">
      <key column="Owner" />
      <one-to-many class="NHibernate.Bugs.Child, NHibernate.Bugs" />
    </set>
  </joined-subclass>
  <class name="NHibernate.Bugs.Child, NHibernate.Bugs" table="Child" proxy="NHibernate.Bugs.Child, NHibernate.Bugs">
    <id name="ObjectId" type="Int32" unsaved-value="-1">
      <generator class="native" />
    </id>
    <version column="VersionCounter" name="VersionCounter" type="Int32" />
    <many-to-one name="Owner" column="Owner" class="NHibernate.Bugs.Parent, NHibernate.Bugs" />
  </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
      Parent obj1 = new Parent();
      ses.Save(obj1);
      ses.Save(new Child(obj1));

The code inside class structure relevant to exception creation is:
  public class Parent : Base
  {
    private ISet m_Childs;
    public void AddChild(Child child)
    {
      // The lazy initialization of ISet is crucial. Without that, the exception does not occure
      if (m_Childs == null)
        m_Childs = new HashedSet();
      m_Childs.Add(child);
    }

    public virtual ICollection Childs
    {
      get { return m_Childs; }
    }
  }

  public class Child
  {
    public Child() : base() { }
    public Child(Parent owner) : base()
    {
      m_Owner = owner;
      m_Owner.AddChild(this);
    }
   /*
   ....
   */
  }


Full stack trace of any exception that occurs:
Code:
NHibernate.Bugs.Bug1Tester.GenerateNullReferenceException : NHibernate.ADOException : could not update: [NHibernate.Bugs.Parent#1]
  ----> System.NullReferenceException : Object reference not set to an instance of an object.
   at NHibernate.Persister.NormalizedEntityPersister.Update(Object id, Object[] fields, Boolean[] includeProperty, Boolean[] includeTable, Object oldVersion, Object obj, SqlString[] sql, ISessionImplementor session)
   at NHibernate.Persister.NormalizedEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session)
   at NHibernate.Impl.ScheduledUpdate.Execute()
   at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
   at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
   at NHibernate.Impl.SessionImpl.Execute()
   at NHibernate.Impl.SessionImpl.Flush()
   at NHibernate.Bugs.Bug1Tester.GenerateNullReferenceException() in C:\Projects\NHibernate.Bugs\Bug1Classes.cs:line 90
--ADOException
   at NHibernate.Driver.DriverBase.GenerateCommand(Dialect dialect, SqlString sqlString)
   at NHibernate.Impl.BatcherImpl.Generate(SqlString sqlString)
   at NHibernate.Impl.BatcherImpl.PrepareCommand(SqlString sql)
   at NHibernate.Persister.NormalizedEntityPersister.Update(Object id, Object[] fields, Boolean[] includeProperty, Boolean[] includeTable, Object oldVersion, Object obj, SqlString[] sql, ISessionImplementor session)


Name and version of the database you are using:

SQL Server 2005


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 4:29 pm 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Forgot to mention that the NullreferenceException is caused by parmeter sqlString==null in DriverBase.GenerateCommand,

which is null because BatcherImpl.Generate had the parameter sqlString == null,

which was null because BatcherImpl.PrepareCommand( SqlString sql )
sql paramtere was null,

which was null because the NormalizedEntityPersister.SqlUpdateStrings[1] was null.

The last one was null because there's nothing to update in "Parent" table, I belive.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 4:33 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Can someone confirm this as bug? Should I report it to JIRA? Any comments?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 5:08 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Please report it, I will look at it later.


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