-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Named query and load-collection. Exception thrown
PostPosted: Thu May 24, 2007 5:08 pm 
Newbie

Joined: Sun Feb 25, 2007 6:59 pm
Posts: 8
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.