• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

class cast exception while retriving hql result

 
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;
}


 
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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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
reply
    Bookmark Topic Watch Topic
  • New Topic