Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Hibernate-Interview-Questions delete() method of hibernate

Have Programming Question? Ask it here!
 
 
 


samar
delete() method of hibernate
1 Answer(s)      3 years and 5 months ago
Posted in : Hibernate Interview Questions


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


Advertisement
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:
 

 

 

DMCA.com