-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: org.hibernate.hql.ast.QuerySyntaxException
PostPosted: Wed Aug 17, 2011 1:12 pm 
Newbie

Joined: Sun Jul 10, 2011 11:16 am
Posts: 6
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.


Top
 Profile  
 
 Post subject: Re: org.hibernate.hql.ast.QuerySyntaxException
PostPosted: Thu Aug 18, 2011 2:28 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
HQL queries use class names not table names:

Code:
from Student stud


The query will return Student objects, not Object[]:

Code:
Student row = (Student) it.next();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.