HI I am getting the below error when I try and run some code using HIBERNATE.
ERROR->" Exception in
thread "main" org.hibernate.MappingException: Unknown entity: Employee"
I have given all the other details below.Please help me out of this error.
Below given my hibernate configuration file(hibernate.config.xml)
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/hibernatedata</property>
<property name="connection.username">root</property>
<property name="connection.password">password</property>
<property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
</session-factory>
</hibernate-configuration>
Here is my session factory code.
MysessionFactory.java
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
public class MySessionFactory {
@SuppressWarnings("deprecation")
static Session getSession(){
Configuration conf = new Configuration();
conf.configure("hibernate.cfg.xml");
SessionFactory sf = conf.buildSessionFactory();
return sf.openSession();
}
}
My POJO class(employee.java)
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Employee{
@Id
private int empid;
private
String empname;
public int getEmpid() {
return empid;
}
public void setEmpid(int empid) {
this.empid = empid;
}
public String getEmpname() {
return empname;
}
public void setEmpname(String empname) {
this.empname = empname;
}
}
And finally my client programme(ClientProgram.java)
import org.hibernate.Session;
public class ClientProgram {
public static void main(String[] args) {
Session session = MySessionFactory.getSession();
session.beginTransaction();
Employee emp =new Employee();
emp.setEmpid(1);
emp.setEmpname("aneek");
session.save(emp);
session.getTransaction().commit();
session.close();
}
}
But whenever I am trying to run this code I am getting the below given error.
"Exception in thread "main" org.hibernate.MappingException: Unknown entity: Employee"