Hibernate Exception: org.hibernate.hql.internal.ast.QuerySyntaxException when retrieving records from a table

In Hibernate 4.0, I want to get a record from a table using session.createQuery("from dbemployee").list(); but Hibernate shows an exception:

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

My POJO class is an 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 dbemployee table in Oracle 11g:

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

Employee.hbm.xml

 <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 resolve this exception. thanks in advance

+4
source share
2 answers

Your request should be:

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

You should use the class name in the query, not the table name.

+3
source

make a request like

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

or

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

In ORMs such as Hibernate and JPA, if you are not using your own queries, you should use the names of the objects / classes in your queries.

+3
source

All Articles