i am facing exception: org.hibernate.hql.ast.QuerySyntaxException: student6 is not mapped [from student6 stud]
my table name is Student6 in sql server database.and pojo class name is Student.
Student.hbm.xml:
Code:
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC"//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
class name="com.vaannila.student.Student" table="Student6">
<meta attribute="class-description">This class contains student details.</meta>
<id name="studentId" type="long" column="STUDENT_ID"><generator class="increment" /></id>
<property name="studentName" type="string" not-null="true"column="STUDENT_NAME" />
<component name="studentAddress" class="com.vaannila.student.Address">
<property name="street" column="ADDRESS_STREET" type="string" length="250" />
<property name="city" column="ADDRESS_CITY" type="string" length="50" />
<property name="state" column="ADDRESS_STATE" type="string" length="50" />
<property name="zipcode" column="ADDRESS_ZIPCODE" type="string" length="10" />
</component>
</class>
</hibernate-mapping>
Code:
public static void main(String[] args) {
Configuration configuration = new Configuration();
configuration.addClass(Student.class);
SessionFactory sessionFactory = configuration.configure().buildSessionFactory();
Session session = sessionFactory.openSession();
try {
String SQL_QUERY ="from student6 stud";
Query query = session.createQuery(SQL_QUERY);
for(Iterator it=query.iterate();it.hasNext();) {
Object[] row = (Object[]) it.next();
System.out.println("STUDENT_ID: " + row[0]);
System.out.println("STUDENT_NAME: " + row[1]);
System.out.println("ADDRESS_STREET: " + row[2]);
System.out.println("ADDRESS_CITY: " + row[3]);
System.out.println("ADDRESS_STATE: " + row[4]);
System.out.println("ADDRESS_ZIPCODE: " + row[5]); }
} catch (HibernateException e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}
}
Student.java:
Code:
package com.vaannila.student;
/**
* This class contains student details.
*/
public class Student implements java.io.Serializable {
private long studentId;
private String studentName;
private Address studentAddress;
public Student() {
}
public Student(String studentName) {
this.studentName = studentName;
}
public Student(String studentName, Address studentAddress) {
this.studentName = studentName;
this.studentAddress = studentAddress;
}
public long getStudentId() {
return this.studentId;
}
public void setStudentId(long studentId) {
this.studentId = studentId;
}
public String getStudentName() {
return this.studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public Address getStudentAddress() {
return this.studentAddress;
}
public void setStudentAddress(Address studentAddress) {
this.studentAddress = studentAddress;
}
}
please suggest.