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:cimitero.rest.TombRESTService.java

@GET
@Path("/{tombId}/customer")
public ResponseDto getCustomerOfTomb(@PathParam("tombId") Integer tombId) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//www.  j a v a 2s  .  c o  m
    TTomb tomb = (TTomb) session.get(TTomb.class, tombId);
    ResponseDto response = new ResponseDto(true);
    if (tomb == null) {
        response.setOk(false);
        response.addError(1, "tomb with id " + tombId + " not found");
    } else {
        if (tomb.getCustomer() != null) {
            TCustomer customer = new TCustomer(tomb.getCustomer().getPersonId(), tomb.getCustomer().getTitle(),
                    tomb.getCustomer().getFirstName(), tomb.getCustomer().getLastName(),
                    tomb.getCustomer().getOtherFirstNames(), tomb.getCustomer().getGebDatum(),
                    tomb.getCustomer().getAddress(), tomb.getCustomer().getTelephoneNumber());
            List<TCustomer> result = new ArrayList<TCustomer>();
            result.add(customer);
            response.setItems(new ItemWrapper(result));
        } else {
            response.setOk(false);
            response.addError(1, "tomb with id " + tombId + " has no customer");
        }
    }
    session.getTransaction().commit();
    return response;
}

From source file:cit360.hibernate.hibernateDemo.java

private static Soda getSoda(Integer SodaId) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;/*from w ww. j av a  2  s.c om*/
    Soda soda = null;

    try {
        tx = session.beginTransaction();
        soda = (Soda) session.get(Soda.class, SodaId);
        tx.commit();
    } catch (HibernateException e) {
        if (tx != null)
            tx.rollback();
        e.printStackTrace();
    } finally {
        session.close();
    }

    return soda;
}

From source file:cl.apr.facade.UsuarioFacade.java

public Usuario getByCodigoUsuario(Session session, Integer id_usuario) throws Exception {
    return (Usuario) session.get(Usuario.class, id_usuario);
}

From source file:cl.model.dao.ArticuloDAO.java

public Articulo consultar(int codigo) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    Articulo articulo = (Articulo) session.get(Articulo.class, codigo);
    if (articulo != null) {
        return articulo;
    } else {/*  w w  w .  j  a v  a 2  s. c  o  m*/
        return null;
    }
}

From source file:cl.model.dao.BoletinDAO.java

public Boletin consultar(int codigo) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    Boletin boletin = (Boletin) session.get(Boletin.class, codigo);
    if (boletin != null) {
        return boletin;
    } else {//from w  ww.  jav a 2 s . c o m
        return new Boletin();
    }
}

From source file:cl.model.dao.CarreraDAO.java

public int consultar(int codigo) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    Carrera carrera = (Carrera) session.get(Carrera.class, codigo);
    if (carrera != null) {
        return 1;
    } else {/*from w ww . j  ava2 s.co  m*/
        return 0;
    }
}

From source file:cl.model.dao.ComponenteDAO.java

public Componente leerComponente(int id) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    Componente c = (Componente) session.get(Componente.class, id);
    //session.close();
    if (c != null) {
        return c;
    } else {/*from  w w  w . ja va2 s  .  com*/
        return null;
    }
}

From source file:cl.model.dao.ComponenteDAO.java

public String actualizarComponete(Componente c) {
    SessionFactory sf;/*from  w  w w . j av a2  s . c o  m*/
    Session session;
    Transaction tx = null;
    String response;
    try {
        sf = HibernateUtil.getSessionFactory();
        session = sf.openSession();
        Componente compo = (Componente) session.get(Componente.class, c.getId());
        compo.setDescripcion(c.getDescripcion());
        compo.setNombre(c.getNombre());
        compo.setEstado(c.isEstado());
        tx = session.beginTransaction();
        session.update(compo);
        tx.commit();
        response = "Componente actualizado exitosamente";
    } catch (Exception ex) {
        tx.rollback();
        response = "No se pudo actualizar el componente";
    }
    return response;
}

From source file:cl.model.dao.ComponenteDAO.java

public String cambiarStatusComponete(int id) {
    SessionFactory sf;// w  w  w.  ja  v  a  2 s . co m
    Session session;
    Transaction tx = null;
    String response;
    try {
        sf = HibernateUtil.getSessionFactory();
        session = sf.openSession();
        Componente compo = (Componente) session.get(Componente.class, id);
        compo.setEstado(!compo.isEstado());
        tx = session.beginTransaction();
        session.update(compo);
        tx.commit();
        response = "El estado de " + compo.getNombre() + " fue actualizado exitosamente";
    } catch (Exception ex) {
        tx.rollback();
        response = "No se pudo actualizar el componente";
    }
    return response;
}

From source file:cl.model.dao.CuentaDAO.java

public int consultar(int codigo) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    Cuenta cuenta = (Cuenta) session.get(Cuenta.class, codigo);
    if (cuenta != null) {
        return 1;
    } else {/*from w  ww  .  j a  v  a  2 s.co m*/
        return 0;
    }
}