Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.demo.impl; import com.demo.dao.CausasDevolucionDao; import com.demo.model.CausasDevolucion; import com.demo.util.HibernateUtil; import com.demo.util.LogSistema; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.Transaction; /** * * @author casiopea */ public class CausasDevolucionImpl implements Serializable, CausasDevolucionDao { @Override public List<CausasDevolucion> getCausasDevolucion() { try { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction t = session.beginTransaction(); List<CausasDevolucion> lista = session.createSQLQuery("select * from causas_devolucion;") .addEntity(CausasDevolucion.class).list(); t.commit(); if (session.isOpen()) { session.close(); } return lista; } catch (HibernateException he) { LogSistema.guardarlog(this.getClass().getName() + " Method: getCausasDevolucion, Excepcion HibernateException: " + he.getMessage()); System.out.println("Error al traer las causas de devolucion"); List<CausasDevolucion> lista = new ArrayList<>(); return lista; } } }