Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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
 
Get out of my mind! Look! A tiny ad!
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!