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.ModoPreparoDetalheAction.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 ava 2  s  .c  o m*/
        Object[] pars = (Object[]) inputPar;
        ModoPreparoVO modoPreparo = (ModoPreparoVO) pars[2];

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

        session.update(modoPreparo);

        session.getTransaction().commit();

        return new VOResponse(modoPreparo);

    } 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.MunicipioDetalheAction.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 a  v  a2 s  .co m
        Object[] pars = (Object[]) inputPar;
        MunicipioVO municipio = (MunicipioVO) pars[2];

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

        return new VOResponse(municipio);

    } 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.NcmDetalheAction.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  .j  ava2 s . c  o m*/
        Object[] pars = (Object[]) inputPar;
        NcmVO ncm = (NcmVO) pars[2];

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

        session.update(ncm);

        session.getTransaction().commit();

        return new VOResponse(ncm);
    } 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.NivelFormacaoDetalheAction.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  v  a 2  s.co m
        Object[] pars = (Object[]) inputPar;
        NivelFormacaoVO nivelFormacao = (NivelFormacaoVO) pars[2];

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

        session.getTransaction().commit();

        return new VOResponse(nivelFormacao);

    } 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.PaisDetalheAction.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  ww .jav a  2 s. com*/
        Object[] pars = (Object[]) inputPar;
        FornecedorVO fornecedor = (FornecedorVO) pars[2];

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

        if (criteria.uniqueResult() != null) {
            throw new Exception("J Existe um Fornecedor Vinculado  Pessoa Selecionada!");
        }

        /**
         *  Implementar if(fornecedor.getContabilConta().getId() == null) { fornecedor.setContabilConta(null); }
         */
        fornecedor.setDataCadastro(new Date());

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

        return new VOResponse(fornecedor);

    } 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.ProdutoDetalheAction.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 a v a  2  s  .  co  m
        Object[] pars = (Object[]) inputPar;
        ProdutoVO produto = (ProdutoVO) pars[2];
        List<FichaTecnicaVO> fichaTecnica = (Vector) pars[3];

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

        Criteria criteria = session.createCriteria(ProdutoVO.class);
        criteria.add(Restrictions.eq("gtin", produto.getGtin()));
        criteria.add(Restrictions.ne("id", produto.getId()));

        if (criteria.uniqueResult() != null) {
            throw new Exception("J existe um GTIN vinculado por outro produto.");
        }

        checaProdutoAlmoxarifado(produto);
        checaProdutoMarca(produto);
        checaIcms(produto);
        checaGrupoTributario(produto);

        if (produto.getCaminhoFotoProduto() != null) {
            String caminhoArquivo = context.getRealPath("/imagens") + System.getProperty("file.separator")
                    + "produtos" + System.getProperty("file.separator") + produto.getGtin() + ".jpg";
            produto.setCaminhoFotoProduto(caminhoArquivo);
            Biblioteca.salvaArquivo(caminhoArquivo, produto.getImagem());
        }

        produto.setDataAlteracao(new Date());
        session.update(produto);

        for (FichaTecnicaVO f : fichaTecnica) {
            f.setProduto(produto);
            session.saveOrUpdate(f);
        }

        session.getTransaction().commit();

        return new VOResponse(produto);

    } 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.ProdutoGrupoDetalheAction.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  va 2s. co  m
        Object[] pars = (Object[]) inputPar;
        ProdutoGrupoVO produtoGrupo = (ProdutoGrupoVO) pars[2];

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

        session.update(produtoGrupo);

        session.getTransaction().commit();

        return new VOResponse(produtoGrupo);

    } 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.ProdutoMarcaDetalheAction.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 .  j ava 2s  .  c  o  m
        Object[] pars = (Object[]) inputPar;
        ProdutoMarcaVO produtoMarca = (ProdutoMarcaVO) pars[2];

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

        session.getTransaction().commit();

        return new VOResponse(produtoMarca);

    } 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.ProdutoSubGrupoDetalheAction.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  a v a 2  s  .c  om*/
        Object[] pars = (Object[]) inputPar;
        ProdutoSubGrupoVO produtoSubgrupo = (ProdutoSubGrupoVO) pars[2];

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

        session.getTransaction().commit();

        return new VOResponse(produtoSubgrupo);

    } 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.ReceitaDetalheAction.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 2 s  . co  m*/
        Object[] pars = (Object[]) inputPar;
        ReceitaVO receita = (ReceitaVO) pars[2];

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

        session.update(receita);

        session.getTransaction().commit();

        return new VOResponse(receita);

    } 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();
        }
    }
}