tags:

views:

93

answers:

2

hello when I used sql query in hibernate (ie hql) I got following error: student is not mapped. [select stud.vStudentName from student as stud]

here is table name in mysql and following is function of select query.

public static void querySubject(Session session) { String sql_query="select stud.vStudentName from student as stud"; Query query1=session.createQuery(sql_query);

  for(Iterator it=query1.iterate();it.hasNext();)
  {
   Object[] row = (Object[]) it.next();

   System.out.println("Subject Name:"+row[0]);

  }
  return;
 }
A: 

This may not be an HQL problem, unless your class is actually named Student for example - HQL is case sensitive. More likely it is a mapping problem. Check if you able to use your student class via the Session.get method. If so, it is just that you haven't mapped this properly.

David M
yes I can use my student class via session.get. so what can be the mapping problem? and how to solve it?
In that case, it could be case sensitivity as I said. Is your class Student or student?
David M
A: 

In HQL Java classes are case sensitive, therefore try

String sql_query="select stud.vStudentName from Student as stud";
samson