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:appcostal.model.DAO.java

public void eliminar(Object obj) {
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;
    se = s.openSession();/* w  w  w  .  j ava 2s. c om*/
    Transaction tx = se.beginTransaction();
    se.delete(obj);
    tx.commit();
    se.close();
}

From source file:appHibernateSebastianLeonte.Main.java

public static void eliminar() {
    SessionFactory session = SessionFactoryUtil.getSessionFactory();
    Session s = session.openSession();
    Transaction transaction = s.beginTransaction();
    System.out.println("Elimiando");
    Vuelos vuelos = (Vuelos) s.load(Vuelos.class, (String) "AB-BY-4811");
    s.delete(vuelos);
    transaction.commit();//  www . j  a  va2s .  c  o m
    s.close();
    session.close();
}

From source file:appointment.businessobject.ManageCustomer.java

public Boolean deleteCustomer(Long CustomerID) {
    Session session = factory.openSession();
    Transaction tx = null;/*  www.  ja v  a 2s .c  o m*/
    try {
        tx = session.beginTransaction();
        Customer customer = (Customer) session.get(Customer.class, CustomerID);
        session.delete(customer);
        tx.commit();
        return true;
    } catch (HibernateException e) {
        if (tx != null) {
            tx.rollback();
        }
        e.printStackTrace();
        return false;
    } finally {
        session.close();
    }
}

From source file:appointment.data.ObjectFactory.java

public void deleteResource(Object cannedObject) {
    Session session = factory.openSession();
    Transaction tx = session.beginTransaction();
    session.delete(cannedObject);
    session.flush();//  www  .jav  a  2  s.c  o m
    tx.commit();

}

From source file:ar.com.hibernate.dao.Dao.java

public void eliminar(E entity) {

    Session session = null;
    try {//from ww  w.  j  a v  a2 s .  co  m
        session = SessionManager.getSessionFactory().openSession();
        Transaction transaction = session.beginTransaction();
        session.delete(entity);
        transaction.commit();
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:ar.edu.unju.fi.apu.dao.imp.mysql.PacienteDAOImp.java

@Override
public void eliminarPaciente(Paciente paciente) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();/* w w w.  ja va2  s.c  o m*/
    session.delete(paciente);
    session.getTransaction().commit();
    session.close();
}

From source file:aseguradora.HospitalVentana.java

private void eliminarHospital() {
    int row = tablaHospital.getSelectedRow();
    try {/*ww w .j a v  a  2 s .  c  o  m*/

        Session session = sesion.openSession();
        Transaction tx = session.beginTransaction();
        Hospital hospital = new Hospital();
        Short cod_h = (row == -1) ? Short.parseShort(etCodHospital.getText().toString())
                : Short.parseShort(tablaHospital.getModel().getValueAt(row, 0).toString());
        hospital = (Hospital) session.load(Hospital.class, cod_h);
        session.delete(hospital);
        tx.commit();
        session.close();
        cargarHospital();
    } catch (HibernateException e) {
        e.printStackTrace();
        if (e.getMessage().contains("" + ERROR_EDITAR_CLAVE_AJENA)) {
            JOptionPane.showMessageDialog(rootPane,
                    "No puedes borrar este hospital, restriccin clave primeria/ajena");
        }
    }
}

From source file:aseguradora.MedicoVentana.java

private void eliminarMedico() {
    int row = tablaMedico.getSelectedRow();
    try {/*w  w  w.j a v a  2  s. c  o  m*/

        Session session = sesion.openSession();
        Transaction tx = session.beginTransaction();
        Medico medico = new Medico();
        Short cod_m = (row == -1) ? Short.parseShort(etCodMedico.getText().toString())
                : Short.parseShort(tablaMedico.getModel().getValueAt(row, 0).toString());
        medico = (Medico) session.load(Medico.class, cod_m);
        session.delete(medico);
        tx.commit();
        session.close();
        cargarMedico();
    } catch (JDBCException e) {
        System.out.println("aqui");
        e.printStackTrace();
        if (e.getMessage().contains("" + ERROR_EDITAR_CLAVE_AJENA)) {
            JOptionPane.showMessageDialog(rootPane,
                    "No puedes borrar este medico, restriccin clave primeria/ajena");
        }
    }
}

From source file:aseguradora.VistaVentana.java

private void eliminarAsegurado() {
    try {/*from   w w w. ja  v  a2  s .c  o  m*/
        Session session = sesion.openSession();
        Transaction tx = session.beginTransaction();
        PolizasAsegurados pa;

        Query q = session
                .createQuery("from PolizasAsegurados as pa " + "where pa.id.codP = ? " + "and pa.id.num = ?");

        q.setInteger(0, Integer.parseInt(etCodPoliza.getText()));
        q.setInteger(1, Integer.parseInt(etNumAsegurado.getText()));

        pa = (PolizasAsegurados) q.uniqueResult();

        session.delete(pa);
        tx.commit();
        session.close();
        cargarVista();
    } catch (JDBCException e) {
        e.printStackTrace();
        if (e.getErrorCode() == ERROR_EDITAR_CLAVE_AJENA) {
            JOptionPane.showMessageDialog(rootPane,
                    "No puedes borrar este asegurado, restriccin clave primeria/ajena");
        }
    }
}

From source file:at.ac.tuwien.infosys.jcloudscale.datastore.hibernate.work.DeleteWork.java

License:Apache License

private void deleteDatastoreModels(Session session, List<DatastoreModel> datastoreModels) {
    for (DatastoreModel datastoreModel : datastoreModels) {
        session.delete(datastoreModel);
    }/*from   w  w  w  . j av  a  2s  .  c  o  m*/
}