Example usage for org.hibernate Session delete

List of usage examples for org.hibernate Session delete

Introduction

In this page you can find the example usage for org.hibernate Session delete.

Prototype

void delete(Object object);

Source Link

Document

Remove a persistent instance from the datastore.

Usage

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

@Override
public void deletePhenoDataSetFieldGroup(PhenoDataSetFieldGroupVO phenoDataSetFieldGroupVO) {
    //Delete all the PhenoFieldDisplay Items linked to the Group
    Session session = getSession();
    //Delete Display
    PhenoDataSetGroup phenoDataSetGroup = phenoDataSetFieldGroupVO.getPhenoDataSetGroup();
    Collection<PhenoDataSetFieldDisplay> phenoDataSetFieldDisplayList = getPhenoDataSetFieldDisplayForPhenoDataSetFieldGrroup(
            phenoDataSetGroup);/*from  ww  w . j a v a2 s .c om*/
    for (PhenoDataSetFieldDisplay phenoDataSetFieldDisplay : phenoDataSetFieldDisplayList) {
        session.delete(phenoDataSetFieldDisplay);
    }
    //Delete picked and linked
    deletePickedCategoriesAndAllTheirChildren(phenoDataSetGroup.getStudy(), phenoDataSetGroup.getArkFunction(),
            phenoDataSetFieldGroupVO.getArkUser());
    //Delete group.
    session.delete(phenoDataSetFieldGroupVO.getPhenoDataSetGroup());
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

public void updateStudy(Study study, Collection<ArkModule> selectedApplications)
        throws CannotRemoveArkModuleException {
    Session session = getSession();

    // session.update(study);
    // execute merge method instead of update to avoid org.hibernate.NonUniqueObjectException
    session.merge(study);//from   w  w  w .j  av  a 2s .c o m

    Collection<LinkStudyArkModule> linkStudyArkModulesToAdd = getModulesToAddList(study, selectedApplications);
    // Determine Removal List here
    Collection<LinkStudyArkModule> linkStudyArkModulesToRemove = getModulesToRemoveList(study,
            selectedApplications);

    // Process the Removal of Linked ArkModules for this study
    for (LinkStudyArkModule linkStudyArkModule : linkStudyArkModulesToRemove) {
        session.delete(linkStudyArkModule);
    }
    // Insert the new modules for the Study
    for (LinkStudyArkModule linkStudyArkModule : linkStudyArkModulesToAdd) {
        session.save(linkStudyArkModule);
    }

    // Flush must be the last thing to call. If there is any other code/logic to be added make sure session.flush() is invoked after that.
    session.flush();
}

From source file:backend.api.FinanceManagement.java

public boolean removeUser(int idUser) // ok
{
    Session session = sf.openSession();
    try {/*from  www .java  2s  .co m*/
        Transaction tx = session.beginTransaction();
        Users user = (Users) session.load(Users.class, idUser);
        if (null != user) {
            session.delete(user);
            tx.commit();
            return true;
        } else {
            return false;
        }

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    } finally {
        session.close();
    }

}

From source file:backend.api.FinanceManagement.java

public boolean removeGroup(int idGroup) // ok
{
    Session session = sf.openSession();
    try {/*from  w ww . j a v  a2  s.  c  o  m*/
        Transaction tx = session.beginTransaction();
        Groups group = (Groups) session.load(Groups.class, idGroup);
        if (null != group) {
            session.delete(group);
            tx.commit();
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    } finally {
        session.close();
    }
}

From source file:backend.api.StorageManagement.java

public boolean removeProduct(int idProduct) //ok
{
    Session session = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {/*from  ww  w  .  j  a v  a  2  s .c o m*/
        Transaction tx = session.beginTransaction();
        Products product = (Products) session.load(Products.class, idProduct);
        if (null != product) {
            session.delete(product);
            tx.commit();
            return true;
        } else {
            return false;
        }
    } finally {
        session.close();
    }
}

From source file:backend.api.StorageManagement.java

public boolean removeCategory(int idCategory) //ok
{
    Session session = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {//from w  w  w  .  j  a v a  2 s.  c  o m
        Transaction tx = session.beginTransaction();
        Category category = (Category) session.load(Category.class, idCategory);
        if (null != category) {
            session.delete(category);
            tx.commit();
            return true;
        } else {
            return false;
        }
    } finally {
        session.close();
    }
}

From source file:backend.api.StorageManagement.java

public boolean removeManufacturer(int idManufacturer) //ok
{
    Session session = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {/*from  ww w  . j  a  v  a 2 s .  c  o  m*/
        Transaction tx = session.beginTransaction();
        Manufacturers manu = (Manufacturers) session.load(Manufacturers.class, idManufacturer);
        if (null != manu) {
            session.delete(manu);
            tx.commit();
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    finally {
        session.close();
    }
}

From source file:backend.api.StorageManagement.java

public boolean removeAttributes(int idAttributes) //ok
{
    Session session = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {//  w  w  w.  ja  va2s. c om
        Transaction tx = session.beginTransaction();
        Category category = (Category) session.load(Category.class, idAttributes);
        if (null != category) {
            session.delete(category);
            tx.commit();
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    finally {
        session.close();
    }
}

From source file:baking.dao.BaseDao.java

License:Open Source License

/**
 * /*www. ja  v  a2  s  . c om*/
 * @description   
 * @author  JiaCao
 * @param obj  
 */

public void delete(Object obj) {
    try {
        Session session = getSession();
        session.delete(obj);
    } catch (RuntimeException re) {
        throw re;
    }
}

From source file:bank.DAO.BillDAO.java

public void deleteBill(List<Bill> result) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from  w w w  .  j av a2  s. c  o  m
    for (Bill p : result) {
        System.out.println("Delete:" + p.getId() + ":" + p.getStart_date());
        session.delete(p);
        //session.flush();
    }
    //session.createSQLQuery("delete from bill where id = 1").executeUpdate();
    session.getTransaction().commit();
}