• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class cast exception while retriving hql result

 
Siddharth Maheshwari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to type cast the result of two pojo , below is the code

List getrecordsList4=new ArrayList();
List mylist=new ArrayList();

getrecordsList4 = getHibernateTemplate().find("select co.chinesename fo.englishname from Company as co , founder as fo where co.companyid=fo.companyid);


if (getrecordsList4 != null && getrecordsList4.size() > 0)
{

Iterator itr = getrecordsList4.iterator();
while (itr.hasNext())
{
Object object= itr.next();
CompanyDTO companyDTO = new CompanyDTO();
companyDTO.setChinesename(company.getChinesename());
mylist.add(companyDTO);

}

return mylist;
}


 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cast each element of the List as Object[],
take out the first element and it will be of type of co.chinesename
second element will be of type of fo.englishname
 
Siddharth Maheshwari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Rahul

I did the same but it is not returning co.chinesename, please advice
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is it returning instead?
 
Siddharth Maheshwari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
paul

List<Object[]> idList =getHibernateTemplate().find("select co.chinesename,fo.fenglishname from Company as co,Founder as fo where co.companyid=fo.companyid and co.companyid=1");

System.out.print(idList.get(0));



output is [Ljava.lang.Object;@1745e95

please advice
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic