5

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

1
  • where is your connection setting file. you made mistake in connection Commented Dec 19, 2012 at 14:39

2 Answers 2

4

Your query should be:

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

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

Sign up to request clarification or add additional context in comments.

Comments

3

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.

1 Comment

That's exactly what I wrote :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.