Hibernate Jars Download Link :(copy and paste in

browser)
https://sourceforge.net/projects/hibernate/files/hibernate3/3.1.3/hibernate-3.1.3.zip/download

Hibernate POJI-POJO Design Pattern with Singletone
SessionFactory (using HibernateUtil):
1) Model Class:
packagecom.app.model;

publicclass Employee {

privateintempId;
private String empName;
privatedoubleempSal;

public Employee() {
super();
}

public Employee(intempId) {
super();
this.empId = empId;
}

public Employee(intempId, String empName,
doubleempSal) {
super();
this.empId = empId;
this.empName = empName;
this.empSal = empSal;
}

publicintgetEmpId() {
returnempId;
}
publicvoidsetEmpId(intempId) {
this.empId = empId;
}
public String getEmpName() {
returnempName;
}

org/dtd/hibernate-mapping- 3.0"encoding="UTF-8"?> <!DOCTYPEhibernate-mappingPUBLIC "-//Hibernate/Hibernate Mapping DTD 3.empSal = empSal. empName=" + empName + ".model. empSal=" + empSal + "]".dtd"> <hibernate-mapping> <classname="com. } } 2)Mapping File: <?xmlversion="1.Employee"table="emptab1"> <idname="empId"column="eid"/> <propertyname="empName"column="ename"length="10"uniqu e="true"/> <propertyname="empSal"column="esal"precision="5"scale ="2"/> </class> </hibernate-mapping> 3)Configuration File: . publicvoidsetEmpName(String empName) { this.app. } @Override public String toString() { return"Employee [empId=" + empId + ".empName = empName.hibernate.0//EN" "http://www. } publicdoublegetEmpSal() { returnempSal. } publicvoidsetEmpSal(doubleempSal) { this.0.

0"encoding="UTF-8"?> <!DOCTYPEhibernate-configurationPUBLIC "-//Hibernate/Hibernate Configuration DTD 3.app.dtd"> <hibernate-configuration> <session-factory> <propertyname="hibernate.username">root</p roperty> <propertyname="hibernate.mysql. importcom.hibernate.Employee.url">jdbc:mysql:/ /localhost:3306/test</property> <propertyname="hibernate.hbm2ddl.password">root</p roperty> <propertyname="hibernate.jdbc.org/dtd/hibernate- configuration-3.xml"/> </session-factory> </hibernate-configuration> 4) POJI (IDao): packagecom.app.connection.connection.dao.model.driver_class">com .Driver</property> <propertyname="hibernate.dialect">org.connection.diale ct.hbm.<?xmlversion="1.0.auto">update</proper ty> <propertyname="hibernate.connection.MySQLDialect</property> <mappingresource="employee. .show_sql">true</property> <propertyname="hibernate.0//EN" "http://www.hibernate.

publicclassHibernateUtil { privatestaticSessionFactorysf=null.dao.buildSessionFactory(). publicvoiddeleteEmployee(intempId).configure(). Transaction tx=null. } } 5)POJO ( DaoImpl) packagecom. importorg. int id=-1. try { .app.model. static{ sf=new Configuration().IEmployeeDao. } packagecom. importcom. public Employee getEmployeeById(intempId). } publicstaticSessionFactorygetSeesionFactory(){ returnsf. importorg. importorg.hibernate.app.hibernate.app.dao.HibernateUtil. importcom. importorg.Configuration.hibernate.Session. publicclassEmployeeDaoHibernateImplimplementsIEmploye eDao{ @Override publicintsaveEmployee(Employee emp) { Session ses=null.SessionFactory.app.hibernate.Employee.Transaction.publicinterfaceIEmployeeDao { publicintsaveEmployee(Employee emp). importcom.app.util.util. publicvoidupdateEmployee(Employee emp).impl.cfg.

Transaction tx=null.openSession(). tx.beginTransaction(). } catch (Exception e) { tx. Transaction tx=null.begin().begin().ses=HibernateUtil. } } @Override publicvoiddeleteEmployee(intempId) { Session ses=null. e.rollback(). } @Override publicvoidupdateEmployee(Employee emp) { Session ses=null. } return id.close().beginTransaction().getSeesionFactory(). }finally{ if(ses!=null) ses. ses. tx=ses. e. tx.openSession().commit(). }finally{ if(ses!=null) ses. try { ses=HibernateUtil.printStackTrace(). tx.save(emp).getSeesionFactory(). } catch (Exception e) { tx.printStackTrace(). id=(Integer)ses.rollback(). try { .close(). tx=ses.update(emp).commit(). tx.

getSeesionFactory().openSession(). } } 6) TEST class:- . tx.delete(new Employee(empId)). } catch (Exception e) { tx. } } @Override public Employee getEmployeeById(intempId) { Session ses=null. Employee emp=null.commit(). Object ob=ses.begin().close(). if(ob!=null) emp=(Employee)ob.beginTransaction(). } returnemp.openSession().rollback(). }finally{ if(ses!=null) ses. e.getSeesionFactory().printStackTrace(). tx.class.close(). tx=ses.beginTransaction(). ses.ses=HibernateUtil. }finally{ if(ses!=null) ses.get(Employee. Transaction tx=null.empId).rollback().printStackTrace(). } catch (Exception e) { tx. tx=ses. try { ses=HibernateUtil. e.

} } .app.app.updateEmployee(new Employee(10.EmployeeDaoHibernateImpl.app. publicclass Test { publicstaticvoid main(String[] args) { IEmployeeDaodao=newEmployeeDaoHibernateImpl().test.dao.36)). 8563.getEmployeeById(10).println(emp).dao.impl.IEmployeeDao. importcom.app. /*dao.model.*/ Employee emp=dao. importcom.36)). "sdsd". System.*/ /*dao.saveEmployee(new Employee(10.out. "AAAA". 523. importcom.Employee.packagecom.