Uploaded image for project: 'NHibernate'
  1. NH-3468

InvalidCastException when deleting entities containing uninitialized lazy components

    Details

      Description

      When trying to delete an entity having an uninitialized lazy component, InvalidCastException is thrown: Unable to cast object of type 'NHibernate.Intercept.UnfetchedLazyProperty' to type xxx.

      I believe the problem lies at NHibernate.Engine.ForeignKeys.Nullifier, at NullifyTransientReferences. This method will try to walk through the component's property values regardless they have been initialized or not, and does not initialize the properties itself, nor does it throw any meaningful exception.
      It would be nice if the uninitialized properties were initialized, or better the lazy properties were initialized only when there are any properties under the component's hierarchy which need to be nullified.
      As we don't use associations and collections in out components, our workaround was to skip "nullification" of uninitialized components at all.

      I have tested this using the following setups, and behavior was all the same: .NET 4.0 + Oracle.DataAccess, .NET 4.0 + System.Data.SQLite, .NET 2.0 + System.Data.SQLite

      The attached test cases are to be imported into the standard NHibernate.Test project.

        Attachments

          Activity

            People

            • Assignee:
              hazzik Alexander Zaytsev
              Reporter:
              gszecsi Gabor Szecsi
            • Votes:
              8 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Who's Looking?