Skip to content

Fetch throws "could not resolve property" error for a property that is not mapped #3352

@cremor

Description

@cremor

I just updated from NHibernate 5.4.2 to 5.4.3 and now one specific query is failing in my application. NHibernate tries to access a property that is not mapped.

I do not yet know the minimum required code to reproduce it, but here is some information:

My model (simplified):

// Mapped as entity
class PlausibilityCheck {
}

// Mapped as readonly entity
class ValidationConfiguration {
  // Mapped as one-to-many with subselect fetching
  public virtual ICollection<PlausibilityCheck> PlausibilityChecks { get; private set; }
}

// Not mapped
class Status {
  // Mapped as many-to-one with join fetching (in the ProjectStatus entity)
  public virtual ValidationConfiguration ValidationConfiguration { get; private set; }
}

// Mapped as entity with a discriminator column (table-per-class-hierarchy)
class ProjectStatus : Status {
}

// Mapped as a subclass of ProjectStatus
class SpecificProjectStatus : ProjectStatus {
  // Mapped as many-to-one (without any fetching)
  public virtual FinancialStatus FinancialStatus { get; set; }
}

// Mapped as an entity (completely unrelated to ProjectStatus)
class FinancialStatus : Status {
}

My query (simplified):

_session
  .Query<SpecificProjectStatus>()
  // This fetch is needed so that the subselect fetching which is defined on the mapping of 'ValidationConfiguration.PlausibilityChecks' works.
  // If I delete this fetch then the query works again, but then I have a select n+1 problem for 'ValidationConfiguration.PlausibilityChecks'.
  .Fetch(x => x.ValidationConfiguration)
  .ToArray();

The exception:

NHibernate.QueryException
  HResult=0x80131500
  Message=could not resolve property: ValidationConfiguration of: MyNamespace.FinancialStatus
  Source=NHibernate
  StackTrace:
   at NHibernate.Persister.Entity.AbstractPropertyMapping.ToType(String propertyName)
   at NHibernate.Linq.Visitors.ResultOperatorProcessors.ProcessFetch.Process(FetchRequestBase resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree, HqlDot memberPath, HqlTreeNode currentNode, IType propType)
   at NHibernate.Linq.Visitors.ResultOperatorProcessors.ProcessFetch.Process(FetchRequestBase resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree, HqlTreeNode currentNode, String sourceAlias)
   at NHibernate.Linq.Visitors.ResultOperatorProcessors.ProcessFetch.Process(FetchRequestBase resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
   at NHibernate.Linq.Visitors.ResultOperatorProcessors.ResultOperatorMap.Process(ResultOperatorBase resultOperator, QueryModelVisitor queryModel, IntermediateHqlTree tree)
   at Remotion.Linq.QueryModelVisitorBase.VisitResultOperators(ObservableCollection`1 resultOperators, QueryModel queryModel)
   at NHibernate.Linq.Visitors.QueryModelVisitor.Visit()
   at NHibernate.Linq.Visitors.QueryModelVisitor.GenerateHqlQuery(QueryModel queryModel, VisitorParameters parameters, Boolean root, Nullable`1 rootReturnType)
   at NHibernate.Linq.NhLinqExpression.Translate(ISessionFactoryImplementor sessionFactory, Boolean filter)
   at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
   at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters)
   at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow)
   at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression)
   at NHibernate.Linq.DefaultQueryProvider.PrepareQuery(Expression expression, IQuery& query)
   at NHibernate.Linq.DefaultQueryProvider.ExecuteList[TResult](Expression expression)
   at NHibernate.Linq.NhQueryable`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at <MyRepository>

Note that NHibernate searches for the property ValidationConfiguration on the entity FinancialStatus. That property exists in the class (it's inherited from its base class), but is not mapped.
Also, the query that throws the exception doesn't even need FinancialStatus. It should not be loaded (only null or a proxy should be set in SpecificProjectStatus.FinancialStatus).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions