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

Fetching a lazy loaded component regression #3164

Closed
nfplee opened this issue Sep 26, 2022 · 14 comments
Closed

Fetching a lazy loaded component regression #3164

nfplee opened this issue Sep 26, 2022 · 14 comments

Comments

@nfplee
Copy link
Contributor

nfplee commented Sep 26, 2022

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

@bahusoid

This comment was marked as outdated.

@bahusoid

This comment was marked as off-topic.

@nfplee

This comment was marked as off-topic.

@bahusoid bahusoid closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2022
@nfplee

This comment was marked as resolved.

@bahusoid

This comment was marked as resolved.

@bahusoid bahusoid reopened this Sep 27, 2022
@nfplee

This comment was marked as resolved.

@bahusoid

This comment was marked as resolved.

@nfplee

This comment was marked as outdated.

@bahusoid

This comment was marked as resolved.

@bahusoid

This comment was marked as resolved.

@nfplee
Copy link
Contributor Author

nfplee commented Sep 28, 2022

Thanks, I'm glad you can reproduce.

Also you don't need to rewrite existing mappings. Instead of writing mapper.Class ...) you can reuse existing mapping class via mapper.AddMapping() or mapper.AddMapping()

Yeah I know but I found it easier to modify if it was all within 1 file.

@bahusoid
Copy link
Member

Test case https://github.com/bahusoid/nhibernate-core/tree/gh3164. Not sure but seems regression from #1922

@bahusoid
Copy link
Member

Fixed by #3171

@nfplee
Copy link
Contributor Author

nfplee commented Sep 30, 2022

Great, thanks @bahusoid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants