Example usage for org.hibernate Session load

List of usage examples for org.hibernate Session load

Introduction

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

Prototype

void load(Object object, Serializable id);

Source Link

Document

Read the persistent state associated with the given identifier into the given transient instance.

Usage

From source file:com.hibernate.dao.ProvedorDAO.java

public void borraProvedor(int idProvedor) {
    Transaction trns = null;/*from ww w  . ja v  a2 s.c om*/
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = session.beginTransaction();
        Provedor provedor = (Provedor) session.load(Provedor.class, new Integer(idProvedor));
        session.delete(provedor);
        session.getTransaction().commit();
    } catch (RuntimeException e) {
        if (trns != null) {
            trns.rollback();
        }
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
}

From source file:com.hibernate.dao.RefaccionDAO.java

public void borraProvedor(int idRefaccion) {
    Transaction trns = null;//w  w w . j  av a2  s  .co  m
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = session.beginTransaction();
        Refaccion refaccion = (Refaccion) session.load(Refaccion.class, new Integer(idRefaccion));
        session.delete(refaccion);
        session.getTransaction().commit();
    } catch (RuntimeException e) {
        if (trns != null) {
            trns.rollback();
        }
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
}

From source file:com.hibernate.dao.ReparaccionDAO.java

public void borraProvedor(int idReparacion) {
    Transaction trns = null;/* w  ww .  j  av a2s .  c  om*/
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = session.beginTransaction();
        Reparacion reparacion = (Reparacion) session.load(Reparacion.class, new Integer(idReparacion));
        session.delete(reparacion);
        session.getTransaction().commit();
    } catch (RuntimeException e) {
        if (trns != null) {
            trns.rollback();
        }
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
}

From source file:com.hibernate.dao.ServicioDAO.java

public void borraServicio(int idServicio) {
    Transaction trns = null;//from   www . j a  v a2  s  .  c  o m
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = session.beginTransaction();
        Servicio reparacion = (Servicio) session.load(Servicio.class, new Integer(idServicio));
        session.delete(reparacion);
        session.getTransaction().commit();
    } catch (RuntimeException e) {
        if (trns != null) {
            trns.rollback();
        }
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
}

From source file:com.hibernate.dao.TelClienteDAO.java

public void borraTelProvedor(int idTelefono) {
    Transaction trns = null;/*  w  ww . j av  a 2s. c  om*/
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = session.beginTransaction();
        TelCliente telefono = (TelCliente) session.load(TelCliente.class, new Integer(idTelefono));
        session.delete(telefono);
        session.getTransaction().commit();
    } catch (RuntimeException e) {
        if (trns != null) {
            trns.rollback();
        }
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
}

From source file:com.hibernate.dao.TelProvedorDAO.java

public void borraTelProvedor(int idTelefono) {
    Transaction trns = null;/*from   w  ww.  j a v a  2s . c o m*/
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = session.beginTransaction();
        Telefono telefono = (Telefono) session.load(Telefono.class, new Integer(idTelefono));
        session.delete(telefono);
        session.getTransaction().commit();
    } catch (RuntimeException e) {
        if (trns != null) {
            trns.rollback();
        }
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
}

From source file:com.humber.java.dao.AlbumDAO.java

public void deleteAlbum(int albumId) {
    Transaction trns = null;//from   www.  j a  va2  s  .  c  o  m
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = session.beginTransaction();
        Album album = (Album) session.load(Album.class, new Integer(albumId));
        session.delete(album);
        session.getTransaction().commit();
    } catch (RuntimeException e) {
        if (trns != null) {
            trns.rollback();
        }
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
}

From source file:com.humber.java.dao.ImageDAO.java

public void deleteImage(int imageId) {
    Transaction trns = null;//from   w w w. j  a  va2 s  .c  o m
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = session.beginTransaction();
        Picture image = (Picture) session.load(Picture.class, new Integer(imageId));
        session.delete(image);
        session.getTransaction().commit();
    } catch (RuntimeException e) {
        if (trns != null) {
            trns.rollback();
        }
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
}

From source file:com.icesoft.icefaces.tutorial.crud.hibernate.RegisterManager.java

License:Apache License

/**
 * Listener for the student id selectOneMenu component value change action.
 * @param ValueChangeEvent representing the new value.
 *//*from  w w w  .  j  av  a2  s.c  o  m*/
public void studentValueChanged(ValueChangeEvent event) {
    if (event.getNewValue() != null) {
        int id = Integer.parseInt(event.getNewValue().toString());
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        currentStudent = (Student) session.load(Student.class, id);
        setStudentCourses();
        session.getTransaction().commit();
    } else {
        currentStudent = new Student();
        setStudentCourses();
    }
}

From source file:com.icesoft.icefaces.tutorial.crud.hibernate.RegisterManager.java

License:Apache License

/**
 * Listener for the add course button click action.
 * @param ActionEvent click action event.
 *//*from   ww w. j ava 2s  .  c  o  m*/
public void addCourseToStudent(ActionEvent event) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();

    currentStudent = (Student) session.get(Student.class, currentStudent.getStudentId());
    currentCourse = (Course) session.load(Course.class, currentCourse.getCourseId());

    currentStudent.getCourses().add(currentCourse);
    currentCourse.getStudents().add(currentStudent);
    // Or persist currentCourse. Either way cascades.
    session.persist(currentStudent);
    setStudentCourses();

    session.getTransaction().commit();
}