This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
str="select * from stud where id=1"; // this will fetch one record.
Student s = (Student) session.createQuery(str);
system.out.println( s.getid + " " + s.getname);
org.hibernate.impl.QueryImpl cannot be cast to Student
Note : Inshort , Its ok if we use iterate if query return multiple records. In above query return only one record so I dont want use iterator. and like this (classname.class, 1). Request all user to solve this.
Your code cannot possibly work as createQuery returns a Query instance, not a database entity (see the documentation). You still need to execute the query to get the results.
However, since you want to find a single entity, you should probably look at something like this.
Since this has nothing to do with Struts, I'll move it to the Hibernate forum if you have any further questions.