Example usage for org.hibernate Hibernate initialize

List of usage examples for org.hibernate Hibernate initialize

Introduction

In this page you can find the example usage for org.hibernate Hibernate initialize.

Prototype

public static void initialize(Object proxy) throws HibernateException 

Source Link

Document

Force initialization of a proxy or persistent collection.

Usage

From source file:com.valco.dao.ClienteDAO.java

public List<Clientes> getClientes() throws Exception {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction tx = null;/* ww  w.  j  a va2s .  c  o  m*/
    List<Clientes> clientes = new ArrayList<Clientes>();
    try {
        tx = session.beginTransaction();
        Criteria q = session.createCriteria(Clientes.class);
        clientes = (List<Clientes>) q.list();
        for (Clientes cliente : clientes) {
            for (NotasDeVenta nota : cliente.getNotasDeVentas()) {
                Hibernate.initialize(nota);
                Hibernate.initialize(nota.getCuentaXCobrar());
            }
        }
        return clientes;

    } catch (HibernateException he) {
        throw new Exception("Ocurri un error al consultar los clientes.");

    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new Exception("Ocurri un error al consultar los clientes.");
        }
    }
}

From source file:com.valco.dao.ClienteDAO.java

public List<Clientes> getClientesConAdeudo() throws Exception {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction tx = null;/*w ww. j ava 2 s . c  om*/
    List<Clientes> clientes = new ArrayList<Clientes>();
    try {
        tx = session.beginTransaction();
        Query q = session.createQuery("FROM Clientes");
        clientes = (List<Clientes>) q.list();
        for (Clientes cliente : clientes) {
            for (NotasDeVenta nota : cliente.getNotasDeVentas()) {
                Hibernate.initialize(nota);
                Hibernate.initialize(nota.getCuentasXCobrars());
            }
        }
        return clientes;

    } catch (HibernateException he) {
        throw new Exception("Ocurri un error al consultar los clientes.");

    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new Exception("Ocurri un error al consultar los clientes.");
        }
    }
}

From source file:com.valco.dao.FacturasDAO.java

public List<Clientes> getFacturas() throws Exception {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction tx = null;/*from  w ww.  ja v  a  2s  . c o  m*/
    List<Clientes> clientes = new ArrayList<Clientes>();
    try {
        tx = session.beginTransaction();
        Criteria q = session.createCriteria(Clientes.class);
        clientes = (List<Clientes>) q.list();
        for (Clientes cliente : clientes) {
            for (NotasDeVenta nota : cliente.getNotasDeVentas()) {
                Hibernate.initialize(nota);
                Hibernate.initialize(nota.getCuentaXCobrar());
            }
        }
        return clientes;

    } catch (HibernateException he) {
        throw new Exception("Ocurri un error al consultar las facturas.");

    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new Exception("Ocurri un error al consultar las facturas.");
        }
    }
}

From source file:com.valco.dao.NotasVentaDAO.java

public List<NotasDeVenta> getNotasDeVentaXCliente(Clientes cliente) throws Exception {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;/*from  ww  w.  j  a v a2s  .co  m*/
    List<NotasDeVenta> notas = new ArrayList<NotasDeVenta>();
    try {
        tx = session.beginTransaction();
        Criteria q = session.createCriteria(NotasDeVenta.class).setFetchMode("cuentasXCobrars", FetchMode.JOIN)
                .add(Restrictions.eq("clientes", cliente));
        notas = (List<NotasDeVenta>) q.list();
        for (NotasDeVenta nota : notas) {
            for (CuentasXCobrar cuenta : nota.getCuentasXCobrars()) {
                Hibernate.initialize(cuenta);

            }
            Hibernate.initialize(nota.getProductosInventarios());
        }
        return notas;

    } catch (HibernateException he) {
        throw new Exception("Ocurri un error al consultar los clientes.");

    } finally {
        try {
            if (session.isOpen()) {
                session.close();
            }
        } catch (HibernateException he) {
            throw new Exception("Ocurri un error al consultar los clientes.");
        }
    }
}

From source file:com.valco.dao.NotasVentaDAO.java

public List<NotasDeVenta> getNotasDeVenta(Repartidores repartidor, Date fechaInicial, Date fechaFinal,
        String estatus) throws Exception {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;/*from ww  w.j  av a2  s .  c o m*/
    List<NotasDeVenta> notas = new ArrayList<NotasDeVenta>();
    try {
        tx = session.beginTransaction();
        Criteria criteria = session.createCriteria(NotasDeVenta.class)
                .add(Restrictions.eq("repartidores", repartidor));
        if (fechaInicial != null && fechaFinal != null) {
            criteria.add(Restrictions.between("fechaDeVenta", fechaInicial, fechaFinal));
        } else if (fechaInicial != null) {
            criteria.add(Restrictions.eq("fechaDeVenta", fechaInicial));
        } else if (fechaFinal != null) {
            criteria.add(Restrictions.eq("fechaDeVenta", fechaFinal));
        }
        if (estatus != null) {
            criteria.add(Restrictions.eq("estatus", estatus));
        }
        notas = (List<NotasDeVenta>) criteria.list();
        for (NotasDeVenta nota : notas) {
            for (CuentasXCobrar cuenta : nota.getCuentasXCobrars()) {
                Hibernate.initialize(cuenta);
            }
        }
        return notas;

    } catch (HibernateException he) {
        throw new Exception("Ocurri un error al consultar las notas.");

    } finally {
        try {
            if (session.isOpen()) {
                session.close();
            }
        } catch (HibernateException he) {
            throw new Exception("Ocurri un error al consultar las notas.");
        }
    }
}

From source file:com.valco.dao.ProductoDAO.java

public ProductosInventario getProductosXCodigoBarrastransferencia(String codigo) throws Exception {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;//from   w w w. j  a v a2  s  . c o m
    ProductosInventario producto = new ProductosInventario();
    try {
        tx = session.beginTransaction();
        Criteria q = session.createCriteria(ProductosInventario.class)
                .add(Restrictions.eq("codigoBarras", codigo));
        producto = (ProductosInventario) q.uniqueResult();
        if (producto != null) {
            Hibernate.initialize(producto.getTranferencias());
            Hibernate.initialize(producto.getTranferencias().getUbicacionesByDestino());
        }
        return producto;

    } catch (HibernateException he) {
        throw new Exception("Ocurri un error al consultar los productos.");

    } finally {
        try {
            if (session.isOpen()) {
                session.close();
            }
        } catch (HibernateException he) {
            throw new Exception("Ocurri un error al consultar los productos.");
        }
    }
}

From source file:com.valco.dao.ProveedorDAO.java

public List<Proveedores> getOdenesProveedores() throws Exception {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction tx = null;//from   w ww.  ja v  a 2  s.co m
    List<Proveedores> proveedores = new ArrayList<Proveedores>();
    try {
        tx = session.beginTransaction();
        Query q = session.createQuery("FROM Proveedores");
        proveedores = (List<Proveedores>) q.list();
        for (Proveedores proveedor : proveedores) {

            for (OrdenesCompra orden : proveedor.getOrdenesCompras()) {

                Hibernate.initialize(orden);

                Hibernate.initialize(orden.getCuentasXPagars());

            }

        }
        return proveedores;

    } catch (HibernateException he) {
        throw new Exception("Ocurri un error al consultar los proveedores.");

    } finally {
        try {
            if (session.isOpen()) {
                session.close();
            }
        } catch (HibernateException he) {
            throw new Exception("Ocurri un error al consultar los proveedores.");
        }
    }
}

From source file:com.vmware.bdd.manager.ClusterEntityManager.java

License:Open Source License

@Transactional
public NodeEntity getNodeWithNicsByMobId(String vmId) {
    NodeEntity nodeEntity = nodeDao.findByMobId(vmId);
    Hibernate.initialize(nodeEntity.getNics());
    return nodeEntity;
}

From source file:com.vmware.thinapp.workpool.WorkpoolInstanceImpl.java

License:Open Source License

@Override
public WorkpoolModel getWorkpoolModel() {
    return txn.execute(new TransactionCallback<WorkpoolModel>() {
        @Override//  w ww  .ja v a  2 s.c  o m
        public WorkpoolModel doInTransaction(TransactionStatus transactionStatus) {
            WorkpoolModel model = getLocalModel();
            // Eagerly load instances since they will be accessed out of session.
            Hibernate.initialize(model.getInstances());
            return (WorkpoolModel) SerializationHelper.clone(model);
        }
    });
}

From source file:com.whynot.checkOtrade.web.dao.ItemRepository.java

public Item findByID(long id) {
    Session session = sessionFactory.openSession();
    Criteria cr = session.createCriteria(Item.class);
    cr.add(Restrictions.eq("id", id));
    Item entity = (Item) cr.uniqueResult();
    try {/*from  ww w  .  j a  va  2s.c o  m*/
        Hibernate.initialize(entity);
    } catch (ObjectNotFoundException e) {
        System.out.println("Item object with id " + id + " not found");
        entity = null;
    } finally {
        if (session != null) {
            session.flush();
            session.close();
        }
    }

    return entity;
}