If I try to call a named query that is also the loader for a persistent collection an exception is thrown. It looks like the because the custom query has two CustomQueryReturns (CollectionReturn and RootReturn) the CustomLoader gets two entity persisters. This results in the "from" IList passed to ArrayHelper.AddAll being a IList of Child[] rather than an IList of Child which then results in the exception. No exception is thrown if the load-collection element is removed from the mapping file.
Is this the intended behavior (because I shouldn't invoke a named query that has a load-collection) or a bug.
Hibernate version:
1.20 GA
Mapping documents:
Code:
<sql-query name="GetChildByParent">
<load-collection alias="Parent.Child" role="Parent.Child"/>
<return class="Child" />
select * from child where parentid = :parentid
</sql-query>
Code between sessionFactory.openSession() and session.close():Code:
IList<Child> children = session.GetNamedQuery("GetChildByParent").SetInt32("parentid", 1).List<Child>();
Full stack trace of any exception that occurs:Code:
System.ArgumentException: The value "System.Object[]" is not of type "Test.Child" and cannot be used in this generic collection.
Parameter name: value
at System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type targetType)
at System.Collections.Generic.List`1.VerifyValueType(Object value)
at System.Collections.Generic.List`1.System.Collections.IList.Add(Object item)
at NHibernate.Util.ArrayHelper.AddAll(IList to, IList from) in D:\CSI\RICS8\Main\External\NHibernate\src\src\NHibernate\Util\ArrayHelper.cs:line 157
at NHibernate.Impl.SessionImpl.ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results) in D:\CSI\RICS8\Main\External\NHibernate\src\src\NHibernate\Impl\SessionImpl.cs:line 5222
at NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters, IList results) in D:\CSI\RICS8\Main\External\NHibernate\src\src\NHibernate\Impl\SessionImpl.cs:line 5208
at NHibernate.Impl.SessionImpl.List[T](NativeSQLQuerySpecification spec, QueryParameters queryParameters) in D:\CSI\RICS8\Main\External\NHibernate\src\src\NHibernate\Impl\SessionImpl.cs:line 5196
at NHibernate.Impl.SqlQueryImpl.List[T]() in D:\CSI\RICS8\Main\External\NHibernate\src\src\NHibernate\Impl\SqlQueryImpl.cs:line 161