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