Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

retrive value not getting

 
madhuchilipi reddy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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.
 
David Madouros
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic