List of usage examples for org.hibernate Session get
Object get(String entityName, Serializable id);
From source file:br.com.proj.tasker.dao.impl.GrupoDAO.java
@Override public Grupo listarPorId(Integer id) { Session session = HibernateUtil.getSessionFactory().openSession(); Grupo grupo = (Grupo) session.get(Grupo.class, id); session.close();/* w w w . jav a 2s . c o m*/ return grupo; }
From source file:br.com.proj.tasker.dao.impl.PessoaDAO.java
@Override public Pessoa listarPorId(Integer id) { Session session = HibernateUtil.getSessionFactory().openSession(); Pessoa pessoa = (Pessoa) session.get(Pessoa.class, id); session.close();// www . ja v a 2s .c om return pessoa; }
From source file:br.com.proj.tasker.dao.impl.ProjetoDAO.java
@Override public Projeto listarPorId(Integer id) { Session session = HibernateUtil.getSessionFactory().openSession(); Projeto proj = (Projeto) session.get(Projeto.class, id); session.close();/*from w w w . j ava2 s . c om*/ return proj; }
From source file:br.com.proj.tasker.dao.impl.TarefaDAO.java
@Override public Tarefa listarPorId(Integer id) { Session session = HibernateUtil.getSessionFactory().openSession(); Tarefa tar = (Tarefa) session.get(Tarefa.class, id); session.close();//from w ww .j av a2 s . c o m return tar; }
From source file:br.com.proj.tasker.dao.impl.TelefoneDAO.java
@Override public Telefone listarPorId(Integer id) { Session session = HibernateUtil.getSessionFactory().openSession(); Telefone tel = (Telefone) session.get(Telefone.class, id); session.close();/*from w w w . ja v a 2 s . com*/ return tel; }
From source file:br.com.pucminas.debt.dao.impl.ProjetoDAOImpl.java
@Override public void alterar(Projeto projeto) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction t = null;//from ww w .ja va2 s . c o m try { t = session.beginTransaction(); Projeto e = (Projeto) session.get(Projeto.class, projeto.getId()); e.setDescricao(projeto.getDescricao()); session.merge(e); session.getTransaction().commit(); FacesContext context = FacesContext.getCurrentInstance(); context.addMessage(null, new FacesMessage("Projeto " + projeto.getNome(), "Alterado com sucesso!")); } catch (HibernateException e) { if (t != null) { t.rollback(); } FacesContext context = FacesContext.getCurrentInstance(); context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro!", "No foi possvel alterar a estria: " + e)); } finally { session.close(); } }
From source file:br.com.wservice.LabRequisicaoFixingDatas.java
/** * Pega LabRequisicao e a lista de LabDetalheRequisicao de novos exame e faz o * update nas datas de Fatura//from ww w . j a v a 2s . c om * * @param reqStCodigo * @param xmlSolicitacao */ public static void arrumandoDatas(String reqStCodigo, List<LabDetalheRequisicao> listNewExames, String strDbName) { if (listNewExames != null && !listNewExames.isEmpty()) { Session session = null; try { session = SessionFactoriByDBName.getCurrentSession4FacesByDbName(strDbName); Transaction tx = session.beginTransaction(); LabRequisicao labRequisicao = (LabRequisicao) session.get(LabRequisicao.class, new Long(reqStCodigo)); // if(labRequisicao.isSalvoNoDb()){} for (LabDetalheRequisicao labDetalheRequisicao : listNewExames) { labDetalheRequisicao.setDerDtFatura(labRequisicao.getReqDtCadastro()); labDetalheRequisicao.setReqDtCadastro(labRequisicao.getReqDtCadastro()); session.update(labDetalheRequisicao); } tx.commit(); } catch (HibernateException xcp) { xcp.printStackTrace(); } finally { if (session != null) { session.close(); } } } else { System.out.println("No h novos exames para arrumar a data da fatura."); } }
From source file:br.edu.ifes.bd2hibernate.cgd.DAO.java
public Object selecionar(int id, Class c) { Object o = null;// w w w. j a v a 2 s. c om try { Session s = HibernateUtil.getSession(); HibernateUtil.begin(); o = s.get(c, id); HibernateUtil.commit(); HibernateUtil.close(); } catch (Exception e) { e.printStackTrace(); } return o; }
From source file:br.edu.ifnmg.ifad.view.ConfiguracaoBean.java
License:Apache License
public void buscar() { try {//from ww w.j a v a 2s. c o m entity = doInTransaction(new PersistenceAction<Configuracao>() { @Override public Configuracao execute(Session s) throws BusinessException { Configuracao configuracao = (Configuracao) s.get(Configuracao.class, 1); return configuracao; } }); if (entity == null) { entity = new Configuracao(1); salvar(); } } catch (BusinessException ex) { Logger.getLogger(ConfiguracaoBean.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:br.edu.unipampa.gerenciadorconcurso.dao.DAO.java
public static boolean excluir(int codigo, Class type) { Session session = HibernateUtil.openSession(); Transaction tx = null;/* w w w . j a v a 2s . com*/ try { tx = session.getTransaction(); tx.begin(); Object object = session.get(type, codigo); session.delete(object); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } session.close(); return false; } finally { session.close(); } return true; }