Home Struts Struts Struts2.2.1 Integration Struts2.2.1 and hibernate integration application

Ask Questions?

View Latest Questions


 
 

Struts2.2.1 and hibernate integration application
Posted on: March 4, 2011 at 12:00 AM
Advertisement
In this application, you will see how to integrate struts2.2.1 and hibernate.

Struts2.2.1 and hibernate integration application


Description

This class is used for accessing data from database table. The list1() method is used to fetch value from the database and delete() method is used to delete rows from the table. It divides the business logic from view part.

Code

package net.roseindia.dao;

import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.classic.Session;
import net.roseindia.Model.AddInformation;
import net.roseindia.hibernateUtil.HibernateUtil;

public class InformationDAO extends HibernateUtil {
public AddInformation add(AddInformation obInformation) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.save(obInformation);
session.getTransaction().commit();
return obInformation;
}

public List<AddInformation> list1() {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List<AddInformation> inforList = null;
try {
inforList = (List<AddInformation>) session.createQuery(
"from AddInformation").list();
} catch (HibernateException he) {
he.toString();
session.getTransaction().rollback();
}
session.getTransaction().commit();
return inforList;
}

public AddInformation delete(int id) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
AddInformation obInformation2 = (AddInformation) session.load(
AddInformation.class, id);
if (null != obInformation2) {
session.delete(obInformation2);
}
session.getTransaction().commit();
return obInformation2;

}

}

Related Tags for Struts2.2.1 and hibernate integration application:


DMCA.com