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
Your query should be:
session.createQuery("from Employee").list();
You have to use the class name in the query, not the table name.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With