• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

retrive value not getting

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i write code like this .table is SUDHAN
Session session=Orasf.currentSession();
String vs="select max(sudhan.sno) from Sudhan sudhan";
Query qry=session.createQuery(vs);
List studList=qry.list();
Object o[]=studList.toArray();
for(int i=0;i<o.length;i++){
Sudhan s=(Sudhan)o[i];
System.out.println(s.getSno());



but i got exception like

Exception in thread "main" java.lang.ClassCastException: java.lang.Long
at org.student.Getting.main(Getting.java:17)
wt is the mistake in the code.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Madhuchilipi,

Anytime you use aggregation in HQL (max, min, count, sum, etc.), you do not get an instance of your object back. You only get a single column value (the max value of your 'sno' column as a Long in this case). To do what you are trying to do, you have to use a subselect. Your query should look like:



Note: You would have to use a subselect with SQL also.
 
reply
    Bookmark Topic Watch Topic
  • New Topic