Vishwas Tyagi
Vishwas Tyagi

Reputation: 86

Hibernate Exception: org.hibernate.hql.internal.ast.QuerySyntaxException, while retrieving records from table

In Hibernate 4.0, i want to retrieve record from table using session.createQuery("from dbemployee").list(); but Hibernate is showing exception:

Hibernate Exception: org.hibernate.hql.internal.ast.QuerySyntaxException: dbemployee is not mapped [from dbemployee]**

My POJO class is Employee

public class Employee implements Serializable {

private static final long serialVersionUID = 1L;
private String empId;
private String empName;
private long empSalary;

public Employee() {
    super();
}

// getters and setters

}

My table dbemployee in Oracle 11g is:

dbemployee:
EMPID varchar2(20)
EMPNAME varchar2(20)
EMPSALARY number(11);

Employee.hbm.xml is

<hibernate-mapping>
  <class name="beanclass.Employee" table="dbemployee">

  <id name="empId" type="java.lang.String" column="EMPID">
  <generator class="assigned"></generator>
   </id>
   <property name="empName"  column="EMPNAME"  type="java.lang.String"/>
   <property  name="empSalary" column="EMPSALARY" type="java.lang.Long" />
  </class>

  </hibernate-mapping>

please help to solve this exception. Thanks in advance

Upvotes: 5

Views: 4711

Answers (2)

Amir Pashazadeh
Amir Pashazadeh

Reputation: 7282

make your query as

 session.createQuery("from Employee").list();

or

session.createQuery("from beanclass.Employee").list();

In an ORM like Hibernate and JPA, when not dealing with native queries you shall use Object/Class names in your queries.

Upvotes: 3

Atropo
Atropo

Reputation: 12531

Your query should be:

 session.createQuery("from Employee").list();

You have to use the class name in the query, not the table name.

Upvotes: 4

Related Questions