MD TALIB ALAM MD TALIB ALAM - 2 years ago 74
Java Question

Geting 'Entity class not found' error while mapping classes to database table by hibernate

Simple pojo class

package practice041116;
public class Cls {
public String name;
public int roll;
public Cls(){}
public String getName() {
return name;
public void setName(String name) { = name;
public int getRoll() {
return roll;
public void setRoll(int roll) {
this.roll = roll;

The main login file

package practice041116;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
public class MainClass {
public static void main(String args[]){
Configuration cnfg=new Configuration();
SessionFactory fact=cnfg.buildSessionFactory();
Session session=fact.openSession();
Transaction tx=session.beginTransaction();
Cls s=new Cls();


The configuration file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate
Configuration DTD 3.0//EN" "
<property name="hibernate.connection.driver_class">
<property name="hibernate.connection.url">
<property name="hibernate.connection.username">
<property name="hibernate.connection.password">
<property name="hibernate.dialect">
<property name="show_sql">true</property>
<mapping resource="practice041116/Cls.hbm.xml" />

Mapping file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
3.0//EN" "">
<class name="Cls" table="cls">
<id name="id" column="id" type="integer"/>
<property name="name" column="NAME" type="string"/>
<property name="roll" column="ROLL" type="integer"/>

I have the specified table in my database but while execute it gives Entity Class not found Exception, i have tried various answer available on the similar question such as this one
and few more from other sources from the net
Hierarchy of the project and the jar files used
Thanks in advance and forgive me if i have done some format mistake on this question as this is the first question i am posting.
Stack trace of Exception

Answer Source

In your mapping file :

<class name="Cls" table="cls">

you don't specify qualified class name but just simple class name. You should replace by :

<class name="practice041116.Cls" table="cls">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download