Hi,
I am getting below exeception & I am new to Hibernate please any one can help me
org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1402)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1424)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
at mypack.ViewEmployee.main(ViewEmployee.java:22)
while executing below code
Code:
package mypack;
[list]import org.hibernate.Transaction;
import org.hibernate.Session;
import org.hibernate.SessionFactory;[/list]
import org.hibernate.cfg.Configuration;
//import mypack.Employee;
import java.util.List;
import java.util.Iterator;
import org.hibernate.Query;
public class ViewEmployee
{
public static void main(String[] args)
{
Session session = null;
SessionFactory factory;
try
{
factory=new Configuration().configure().buildSessionFactory();//line 22
session=factory.openSession();
Transaction tr=session.beginTransaction();
Query query=session.createQuery("from Employee e");
List list=query.list();
Iterator iter=list.iterator();
while(iter.hasNext())
{
System.out.println(iter.next());
}
tr.commit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="mypack.Employee" table="emp1234">
<id name="eid" column="eid">
<generator class="assigned"/>
</id>
<property name="ename">
<column name="ename" />
</property>
<property name="esal">
<column name="esal"/>
</property>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="current_session_context_class">thread</property>
<property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
<property name="hibernate.connection.url">jdbc:db2:DEMO1</property>
<property name="hibernate.connection.username">nimesh.hindocha</property>
<property name="hibernate.connection.password">hardwork@321</property>
<!-- <property name="hibernate.connection.pool_size">10</property> -->
<property name="show_sql">true</property>
<property name="hibernate.dialect">hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="Employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>
package mypack;
public class Employee
{
public int eid,esal;
public String ename ;
public Employee()
{
}
public Employee(int eid,String ename,int esal)
{
this.eid=eid;
this.ename=ename;
this.esal=esal;
}
public int getEid() {
return eid;
}
public void setEid(int eid) {
this.eid = eid;
}
public int getEsal() {
return esal;
}
public void setEsal(int esal) {
this.esal = esal;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
}