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.  [ 2 posts ] 
Author Message
 Post subject: HQL returns list of objects[] instead of the type I set
PostPosted: Mon Jun 18, 2007 10:51 pm 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
My HQL is (unexpectedly) returning a list of objects[] rather than the entity I have specified in the HQL (and the generic List method).

It seems to be trying to do a Report Query (which would happen if I specified select items). But I simply want a list of Accounts - see code below.

After running the query below, I can't call List<Account> because it throws this error:
System.ArgumentException: The value "System.Object[]" is not of type "Account" and cannot be used in this generic collection.

But if I change it to
Code:
IList bla = query.List();
then I can see that it has returned 5 distinct objects, each one corresponding to the joins I have made. If this is some feature I didn't know about... all good and well, otherwise can anyone explain why it's giving me lists of objects[] instead type 'Account'?

Code:
IQuery query =
            Session.CreateQuery(
               "from Account account join account.Type as type "
               + "join type.Product as product "
               + "join account.AccountCustodianAccounts as aca "
               + "join aca.CustodianAccount "
               + "where product.Name = :ProductName");
         query.SetString("ProductName", "Nice Product");

         IList bla = query.List();
         // this will throw an exception -> IList<Account> accounts = query.List<Account>();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 3:07 am 
Newbie

Joined: Tue May 08, 2007 11:25 am
Posts: 15
Hi,

this is normal because you make joins and you did not specify a "select".

So you should write this :

" select account from Account account "
+ " join account.Type as type "
+ "join type.Product as product "
+ "join account.AccountCustodianAccounts as aca "
+ "join aca.CustodianAccount "
+ "where product.Name = :ProductName");
query.SetString("ProductName", "Nice Product")


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

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.