Example usage for org.hibernate Session get

List of usage examples for org.hibernate Session get

Introduction

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

Prototype

Object get(String entityName, Serializable id);

Source Link

Document

Return the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance.

Usage

From source file:Category.categoryGetter.java

public static Category getCategoryById(int categoryId) {
    Session session;
    Category category = new Category();
    try {//  w  ww.  ja v a2  s  .  co m
        session = HibernateUtil.getSessionFactory().openSession();

        category = (Category) session.get(Category.class, categoryId);
        Hibernate.initialize(category);
        // List<Category> Categoryresult = criteria.list();

    } catch (HibernateException e) {
        throw e;
    }
    return category;
}

From source file:Category.categorySetter.java

public static void updateCategoryById(Integer categoryId, String categoryName, String categoryDescription,
        String categoryType) {/*from  w  w w  .  j a  v  a2 s  .co  m*/
    Session session2 = HibernateUtil.getSessionFactory().openSession();
    session2.beginTransaction();
    Category updateCat = new Category();
    updateCat = (Category) session2.get(Category.class, categoryId);
    Hibernate.initialize(updateCat);
    updateCat.setCategoryName(categoryName);
    updateCat.setCategoryDescription(categoryDescription);
    updateCat.setCategoryType(categoryType);
    session2.merge(updateCat);
    session2.saveOrUpdate(updateCat);
    session2.getTransaction().commit();

}

From source file:cd_modelos_dao.ClientesDAO.java

public Clientes consultarClientePorCedula(String cedula) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Clientes ser = (Clientes) s.get(Clientes.class, cedula);
    s.close();//from w  w w . j  ava 2 s .co  m
    if (ser != null) {
        return ser;
    }
    return null;
}

From source file:cd_modelos_dao.ComprasDAO.java

public ComprasPlanta consultarCompraPorId(int id) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    ComprasPlanta ser = (ComprasPlanta) s.get(ComprasPlanta.class, id);
    List<PlantasCompra> listado = new LinkedList<>();
    Query q = s.createQuery("from PlantasCompra where id_compras_planta = " + id);
    try {//from   w  w  w  . j a va 2  s .  c  o  m
        listado = q.list();

    } catch (Exception e) {
        System.out.println("____________________________________________________");
        System.out.println(e);
        System.out.println("____________________________________________________");
    }
    for (int i = 0; i < listado.size(); i++) {
        Plantas p = (Plantas) s.get(Plantas.class, listado.get(i).getEtapasPlanta().getPlantas().getId());
        Etapas p1 = (Etapas) s.get(Etapas.class, listado.get(i).getEtapasPlanta().getEtapas().getId());
        listado.get(i).setEtapasPlanta(new EtapasPlanta());
        listado.get(i).getEtapasPlanta().setPlantas(p);
        listado.get(i).getEtapasPlanta().setEtapas(p1);
    }

    Set<PlantasCompra> listado2 = new HashSet<>(listado);
    ser.setPlantasCompras(listado2);
    s.close();
    if (ser != null) {
        return ser;
    }
    return null;
}

From source file:cd_modelos_dao.EmpleadosDAO.java

public Empleados consultarEmpleadoPorCedula(String cedula) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Empleados ser = (Empleados) s.get(Empleados.class, cedula);
    s.close();//w  w  w. j  a  va 2 s. co  m
    if (ser != null) {
        return ser;
    }
    return null;
}

From source file:cd_modelos_dao.PlantasDAO.java

public Plantas consultarPlantaPorId(int id) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Plantas planta = (Plantas) s.get(Plantas.class, id);
    s.close();/*from w  ww. j  av a  2s  . c  om*/
    if (planta != null) {
        return planta;
    }
    return null;
}

From source file:cd_modelos_dao.PlantasDAO.java

public VentasPlanta consultarIngresosPlanta(int id) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    VentasPlanta ser = (VentasPlanta) s.get(VentasPlanta.class, id);
    List<PlantasVenta> listado = new LinkedList<>();
    Query q = s.createQuery("from PlantasVenta where plantas_id = " + id);
    try {/*from  w w  w .  j a v a  2  s  .  c  o m*/
        listado = q.list();

    } catch (Exception e) {
        System.out.println("____________________________________________________");
        System.out.println(e);
        System.out.println("____________________________________________________");
    }
    for (int i = 0; i < listado.size(); i++) {
        Plantas p = (Plantas) s.get(Plantas.class, listado.get(i).getEtapasPlanta().getPlantas().getId());
        Etapas p1 = (Etapas) s.get(Etapas.class, listado.get(i).getEtapasPlanta().getEtapas().getId());
        EtapasPlanta ePlanta = (EtapasPlanta) s.get(EtapasPlanta.class,
                listado.get(i).getEtapasPlanta().getId());
        listado.get(i).setEtapasPlanta(new EtapasPlanta());
        listado.get(i).getEtapasPlanta().setPlantas(p);
        listado.get(i).getEtapasPlanta().setEtapas(p1);
        listado.get(i).getEtapasPlanta().setPrecioVenta(ePlanta.getPrecioVenta());
    }

    Set<PlantasVenta> listado2 = new HashSet<>(listado);
    ser.setPlantasVentas(listado2);
    s.close();
    if (ser != null) {
        return ser;
    }
    return null;
}

From source file:cd_modelos_dao.PlantasDAO.java

public ComprasPlanta consultarEgresosPlanta(int id) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    ComprasPlanta ser = (ComprasPlanta) s.get(ComprasPlanta.class, id);
    List<PlantasCompra> listado = new LinkedList<>();
    Query q = s.createQuery("from PlantasCompra where plantas_id = " + id);
    try {/* w w w.j  a  v  a 2s . c om*/
        listado = q.list();

    } catch (Exception e) {
        System.out.println("____________________________________________________");
        System.out.println(e);
        System.out.println("____________________________________________________");
    }
    for (int i = 0; i < listado.size(); i++) {
        System.out.println(listado.size());
        Plantas p = (Plantas) s.get(Plantas.class, listado.get(i).getEtapasPlanta().getPlantas().getId());
        Etapas p1 = (Etapas) s.get(Etapas.class, listado.get(i).getEtapasPlanta().getEtapas().getId());
        EtapasPlanta ePlanta = (EtapasPlanta) s.get(EtapasPlanta.class,
                listado.get(i).getEtapasPlanta().getId());
        listado.get(i).setEtapasPlanta(new EtapasPlanta());
        listado.get(i).getEtapasPlanta().setPlantas(p);
        listado.get(i).getEtapasPlanta().setEtapas(p1);
        listado.get(i).getEtapasPlanta().setPrecioCompra(ePlanta.getPrecioCompra());
    }

    Set<PlantasCompra> listado2 = new HashSet<>(listado);
    ser.setPlantasCompras(listado2);
    s.close();
    if (ser != null) {
        return ser;
    }
    return null;
}

From source file:cd_modelos_dao.ProveedoresDAO.java

public Proveedores consultarproveedorPorCedula(String cedula) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Proveedores ser = (Proveedores) s.get(Proveedores.class, cedula);
    s.close();// w  w w .  j  a  va 2  s  . c  o m
    if (ser != null) {
        return ser;
    }
    return null;
}

From source file:cd_modelos_dao.ReportesDeComprasDAO.java

public List<PlantasCompra> consultarCompraPlanta(int id) {
    List<PlantasCompra> lista = new LinkedList<>();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Query q = s.createQuery("from PlantasCompra where id_compras_planta = " + id);
    lista = q.list();//from w w  w. j  a  va  2 s.c om

    for (PlantasCompra sc : lista) {
        Plantas ser = (Plantas) s.get(Plantas.class, sc.getEtapasPlanta().getPlantas().getId());
        EtapasPlanta et = (EtapasPlanta) s.get(EtapasPlanta.class, sc.getEtapasPlanta().getId());

        sc.setEtapasPlanta(et);
        sc.getEtapasPlanta().setPlantas(ser);
    }

    s.close();
    return lista;
}