Package DAO

Source Code of DAO.PlanoAcaoDao

package DAO;

import Entidade.PlanoAcao;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

public class PlanoAcaoDao {
   
    public List<PlanoAcao> listarPlanoAcao() {
        Session session = HibernateUtil.getSessionFactory().openSession();
        List<PlanoAcao> planAcoes = null;
        try {
            planAcoes = session.getNamedQuery("PlanoAcao.findAll").list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        session.close();
        return planAcoes;
    }
   
    public PlanoAcao consultarPorId(Integer codigo) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Query lista = session.createQuery("From PlanoAcao where codigo = :codigo");
        lista.setInteger("codigo", codigo);
        PlanoAcao resultado = (PlanoAcao) lista.uniqueResult();
        session.getTransaction().commit();
        session.close();
        return resultado;
    }
    public void salvar(PlanoAcao planoAcao){
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        session.save(planoAcao);
        session.getTransaction().commit()
        session.close();
    }
}
TOP

Related Classes of DAO.PlanoAcaoDao

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.