-->
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.  [ 3 posts ] 
Author Message
 Post subject: query.list() type casting
PostPosted: Wed Dec 22, 2010 12:56 am 
Newbie

Joined: Tue Dec 14, 2010 7:48 am
Posts: 10
when iam using query.list() then it return smultiple rows.....

it may return object[]


thats why iam unable to convert into a list<LoanDar>

LoanDar is a pojo


how to type caste a query.list() if it returns object array (multiple rows)


Top
 Profile  
 
 Post subject: Re: query.list() type casting
PostPosted: Wed Dec 22, 2010 2:34 am 
Newbie

Joined: Tue Dec 21, 2010 8:21 am
Posts: 5
query.list() always returns the object array
it has to be type casted using iterator in the below manner

ArrayList list = (ArrayList)query.list();
Iterator lt=list.iterator();
for(int i=0; i<list.size();i++){
//Userdao is a pojo class having setXXX() and getXXX() functions

Userdao qux = ( Userdao) lt.next();
System.out.println(qux.getPassword());
}

just check this and let me know


Top
 Profile  
 
 Post subject: Re: query.list() type casting
PostPosted: Wed Dec 22, 2010 6:16 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
it will only return an object array if you ask for it, for example if you select multiple fields of an entity instead selecting a single mapped type.
If your query is loading many rows of "LoanDar" then you can just cast the result to a List<LoanDar> without any processing.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.