delete() method of hibernate

delete() method of hibernate

Define the use of delete() method of hibernate? Example.

View Answers

March 8, 2011 at 7:03 PM

Hi Samar,

The delete() is a method of hibernate session. It generates a delete query for deletion of object from database..

Example :

package net.roseindia.dao;    
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 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;
    }
}

Thanks..









Related Tutorials/Questions & Answers:

Ads