Skip to content

GenericADOException on not nullable mapped property with null value on db #3711

@DaveLaa

Description

@DaveLaa

I just faced this error message that is new to me. In older versions of NHibernate we never had this problem. I now use V5.6 but it was also in V5.5.3 already... I don't know exactly when it came up...

I have a column "UnixStart" that ist long (not nullable!) mapped. On db we have rare entries that have null as value in this column.

[Property(Column = "UNIX_START")] public virtual long UnixStart { get; set; }

Asking NHibernate to get the entity, the value of the mapped property is set to the default value of its data type (0 in this case) which is the standard behaviour like older versions. This is the behaviour i expect from NHibernate.

so
...Query().Where(...).ToArray();

works as expected.

If i now query the entity and map it to a new type, i get the exception instead of the default value:

...Query().Where(...).Select( p=> new {p.UnixStart,...} ).ToArray();
or even
...Query().Where(...).Select( p=>p.UnixStart ).ToArray();

generates:

NHibernate.Exceptions.GenericADOException
HResult=0x80131500
Message=Could not execute query[SQL: SQL not available]
Source=NHibernate
StackTrace:
at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results, Object filterConnection)
at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results)
at NHibernate.Impl.AbstractSessionImpl.List[T](IQueryExpression query, QueryParameters parameters)
at NHibernate.Impl.AbstractQueryImpl2.ListT
at NHibernate.Linq.DefaultQueryProvider.ExecuteList[TResult](Expression expression)
at NHibernate.Linq.NhQueryable1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Collections.Generic.SegmentedArrayBuilder1.AddNonICollectionRangeInlined(IEnumerable1 source) at System.Linq.Enumerable.<ToArray>g__EnumerableToArray|314_0[TSource](IEnumerable1 source)
...

funnily
...Query().Where(...).Select( p=>(long?)p.UnixStart ).ToArray();
works. Although the data type of UnixStart is long in the entity i get an array of long? with correct db values.

Can anyone confirm this "Bug" as something that should be repaired in the current version? Or is this the behaviour i have to deal with now?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions