MD TALIB ALAM MD TALIB ALAM - 1 month ago 7
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) {
this.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();
cnfg.configure("hibernate.cfg.xml");
SessionFactory fact=cnfg.buildSessionFactory();
Session session=fact.openSession();
Transaction tx=session.beginTransaction();
Cls s=new Cls();
s.setName("Taleev");
s.setRoll(23);
session.save(s);
tx.commit();


}
}

The configuration file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate
Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-
configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="hibernate.connection.url">
jdbc:microsoft:sqlserver://171.8.9.1;DatabaseName:test
</property>
<property name="hibernate.connection.username">
username
</property>
<property name="hibernate.connection.password">
password
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="show_sql">true</property>
<mapping resource="practice041116/Cls.hbm.xml" />
</session-factory>
</hibernate-configuration>


Mapping file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<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"/>
</class>
</hibernate-mapping>


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

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">