Skip to content

Fetching a lazy loaded component regression #3164

Closed
@nfplee

Description

@nfplee

I have identified a regression introduced in version 5.3.0. It happens when trying to fetch a lazy loaded component which has a read-only property and is mapped as an interface.

It's a little querky to explain but I've tried to produce a minimal sample to show you the issue.

Please see the attached application (making sure to set the connection string). The database must have the following structure:

CREATE TABLE [dbo].[ContentItems](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](100) NOT NULL,
	[PageTitle] [nvarchar](1024) NULL
)

INSERT INTO [dbo].[ContentItems] ([Name]) VALUES ('Test')

SQL above edited after realising that the table must have data to reproduce.

  var contentItems = await session.Query<ContentItem>()
      .Fetch(i => i.Head)
      .ToListAsync();

Exception:

NHibernate.Exceptions.GenericADOException
  Message=could not execute query
[ select contentite0_.Id as id1_0_, contentite0_.Name as name2_0_, contentite0_.PageTitle as pagetitle3_0_ from ContentItems contentite0_ ]
  StackTrace:
   at NHibernate.Loader.Loader.<DoListAsync>d__38.MoveNext()
...

  This exception was originally thrown at this call stack:
  System.IndexOutOfRangeException: formula0_
   at System.Data.ProviderBase.BasicFieldNameLookup.GetOrdinal(String fieldName)
   at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
   at NHibernate.Driver.NHybridDataReader.GetOrdinal(String name)
   at NHibernate.Type.NullableType.NullSafeGet(DbDataReader rs, String name, ISessionImplementor session)
   at NHibernate.Type.NullableType.NullSafeGet(DbDataReader rs, String[] names, ISessionImplementor session, Object owner)
   at NHibernate.Type.NullableType.NullSafeGetAsync(DbDataReader rs, String[] names, ISessionImplementor session, Object owner, CancellationToken cancellationToken)
--- End of stack trace from previous location ---
   at NHibernate.Type.ComponentType.HydrateAsync(DbDataReader rs, String[] names, ISessionImplementor session, Object owner, CancellationToken cancellationToken)
   at NHibernate.Persister.Entity.AbstractEntityPersister.HydrateAsync(DbDataReader rs, Object id, Object obj, String[][] suffixedPropertyColumns, ISet`1 fetchedLazyProperties, Boolean allProperties, Int32[] indexes, ISessionImplementor session, CancellationToken cancellationToken)
   at NHibernate.Loader.Loader.LoadFromResultSetAsync(DbDataReader rs, Int32 i, Object obj, ILoadable persister, EntityKey key, LockMode lockMode, ILoadable rootPersister, ISessionImplementor session, CancellationToken cancellationToken)
   at NHibernate.Loader.Loader.InstanceNotYetLoadedAsync(DbDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session, CancellationToken cancellationToken)
   at NHibernate.Loader.Loader.GetRowAsync(DbDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session, Boolean mustLoadMissingEntity, Action`2 cacheBatchingHandler, CancellationToken cancellationToken)
   at NHibernate.Loader.Loader.GetRowFromResultSetAsync(DbDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies, IResultTransformer forcedResultTransformer, QueryCacheResultBuilder queryCacheResultBuilder, Action`2 cacheBatchingHandler, CancellationToken cancellationToken)
   at NHibernate.Loader.Loader.DoQueryAsync(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies, IResultTransformer forcedResultTransformer, QueryCacheResultBuilder queryCacheResultBuilder, CancellationToken cancellationToken)
   at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollectionsAsync(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies, IResultTransformer forcedResultTransformer, QueryCacheResultBuilder queryCacheResultBuilder, CancellationToken cancellationToken)
   at NHibernate.Loader.Loader.DoListAsync(ISessionImplementor session, QueryParameters queryParameters, IResultTransformer forcedResultTransformer, QueryCacheResultBuilder queryCacheResultBuilder, CancellationToken cancellationToken)

Test NHibernate.zip

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions