Example usage for org.hibernate Session update

List of usage examples for org.hibernate Session update

Introduction

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

Prototype

void update(Object object);

Source Link

Document

Update the persistent instance with the identifier of the given detached instance.

Usage

From source file:com.bakeryfactory.cadastros.servidor.SetorDetalheAction.java

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {//ww  w.  j  av a2s  .c o m
        Object[] pars = (Object[]) inputPar;
        SetorVO setor = (SetorVO) pars[2];

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        session.update(setor);
        session.getTransaction().commit();

        return new VOResponse(setor);

    } catch (Exception ex) {
        ex.printStackTrace();
        if (session != null) {
            session.getTransaction().rollback();
        }
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

From source file:com.bakeryfactory.cadastros.servidor.SindicatoDetalheAction.java

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/*ww  w. j  ava 2  s .c  om*/
        Object[] pars = (Object[]) inputPar;
        SindicatoVO sindicato = (SindicatoVO) pars[2];

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        if (sindicato.getContabilConta().getId() == null) {
            sindicato.setContabilConta(null);
        }

        session.update(sindicato);
        session.getTransaction().commit();

        return new VOResponse(sindicato);

    } catch (Exception ex) {
        ex.printStackTrace();
        if (session != null) {
            session.getTransaction().rollback();
        }
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

From source file:com.bakeryfactory.cadastros.servidor.SituacaoColaboradorDetalheAction.java

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {//from  w  w  w.java2  s.c o  m
        Object[] pars = (Object[]) inputPar;
        SituacaoColaboradorVO situacaoColaborador = (SituacaoColaboradorVO) pars[2];

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        session.update(situacaoColaborador);

        session.getTransaction().commit();

        return new VOResponse(situacaoColaborador);

    } catch (Exception ex) {
        if (session != null) {
            session.getTransaction().rollback();
        }
        ex.printStackTrace();
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

From source file:com.bakeryfactory.cadastros.servidor.SituacaoForCliDetalheAction.java

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/*  www  .  j  a va2s.co m*/
        Object[] pars = (Object[]) inputPar;
        SituacaoForCliVO situacaoForCli = (SituacaoForCliVO) pars[2];

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        session.update(situacaoForCli);

        session.getTransaction().commit();

        return new VOResponse(situacaoForCli);

    } catch (Exception ex) {
        if (session != null) {
            session.getTransaction().rollback();
        }
        ex.printStackTrace();
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

From source file:com.bakeryfactory.cadastros.servidor.TipoAdmissaoDetalheAction.java

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {//  ww w  .  jav  a  2 s  . com
        Object[] pars = (Object[]) inputPar;
        TipoAdmissaoVO tipoAdmissao = (TipoAdmissaoVO) pars[2];

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        session.update(tipoAdmissao);

        session.getTransaction().commit();

        return new VOResponse(tipoAdmissao);

    } catch (Exception ex) {
        if (session != null) {
            session.getTransaction().rollback();
        }
        ex.printStackTrace();
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

From source file:com.bakeryfactory.cadastros.servidor.TipoColaboradorDetalheAction.java

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {//w w  w  .j  a v a  2s. co m
        Object[] pars = (Object[]) inputPar;
        TipoColaboradorVO tipoColaborador = (TipoColaboradorVO) pars[2];

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        session.update(tipoColaborador);

        session.getTransaction().commit();

        return new VOResponse(tipoColaborador);

    } catch (Exception ex) {
        if (session != null) {
            session.getTransaction().rollback();
        }
        ex.printStackTrace();
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

From source file:com.bakeryfactory.cadastros.servidor.TipoRelacionamentoDetalheAction.java

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/*from  w w w  . j av a  2s. c om*/
        Object[] pars = (Object[]) inputPar;
        TipoRelacionamentoVO tipoRelacionamento = (TipoRelacionamentoVO) pars[2];

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        session.update(tipoRelacionamento);
        session.getTransaction().commit();

        return new VOResponse(tipoRelacionamento);

    } catch (Exception ex) {
        ex.printStackTrace();
        if (session != null) {
            session.getTransaction().rollback();
        }
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

From source file:com.bakeryfactory.cadastros.servidor.TransportadoraDetalheAction.java

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {//from   ww w  .jav a  2s . c  o  m
        Object[] pars = (Object[]) inputPar;
        TransportadoraVO transportadora = (TransportadoraVO) pars[2];

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        Criteria criteria = session.createCriteria(TransportadoraVO.class);
        criteria.add(Restrictions.eq("pessoa", transportadora.getPessoa()));
        criteria.add(Restrictions.ne("id", transportadora.getId()));

        if (criteria.uniqueResult() != null) {
            throw new Exception("J existe um Cliente vinculado  pessoa selecionada.");
        }

        if (transportadora.getContabilConta().getId() == null) {
            transportadora.setContabilConta(null);
        }

        session.update(transportadora);

        session.getTransaction().commit();

        return new VOResponse(transportadora);

    } catch (Exception ex) {
        if (session != null) {
            session.getTransaction().rollback();
        }
        ex.printStackTrace();
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

From source file:com.bakeryfactory.cadastros.servidor.UfDetalheAction.java

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/*w  w  w.jav  a 2  s  .c  om*/
        Object[] pars = (Object[]) inputPar;
        UfVO uf = (UfVO) pars[2];

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        session.update(uf);

        session.getTransaction().commit();

        return new VOResponse(uf);

    } catch (Exception ex) {
        if (session != null) {
            session.getTransaction().rollback();
        }
        ex.printStackTrace();
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

From source file:com.bakeryfactory.cadastros.servidor.UnidadeProdutoDetalheAction.java

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/*from   www  .j  a v  a 2s . c o m*/
        Object[] pars = (Object[]) inputPar;
        UnidadeProdutoVO unidadeProduto = (UnidadeProdutoVO) pars[2];

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        session.update(unidadeProduto);

        session.getTransaction().commit();

        return new VOResponse(unidadeProduto);

    } catch (Exception ex) {
        if (session != null) {
            session.getTransaction().rollback();
        }
        ex.printStackTrace();
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}