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.CausasDevolucionConceptoDao; import com.demo.model.CausasDevolucionConcepto; 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 CausasDevolucionConceptoImpl implements Serializable, CausasDevolucionConceptoDao { @Override public List<CausasDevolucionConcepto> getCausaDevoConcepPorId(int idCausaDevolucion) { try { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction t = session.beginTransaction(); List<CausasDevolucionConcepto> lista = session.createSQLQuery( "select * from causas_devolucion_concepto c where c.causas_devolucion_idcausas_devolucion = " + idCausaDevolucion + ";") .addEntity(CausasDevolucionConcepto.class).list(); t.commit(); if (session.isOpen()) { session.close(); } return lista; } catch (HibernateException he) { LogSistema.guardarlog(this.getClass().getName() + " Method: getCausaDevoConcepPorId, Excepcion HibernateException: " + he.getMessage()); System.out.println("Error al traer las conceptos de devolucion"); List<CausasDevolucionConcepto> lista = new ArrayList<>(); return lista; } } @Override public List<CausasDevolucionConcepto> getCausaDevoConcepEntreId(int id1, int id2) { try { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction t = session.beginTransaction(); List<CausasDevolucionConcepto> lista = session.createSQLQuery( "select * from causas_devolucion_concepto c where c.idcausas_devolucion_concepto >= " + id1 + " and c.idcausas_devolucion_concepto <= " + id2 + " union select * from causas_devolucion_concepto c where c.idcausas_devolucion_concepto =47") .addEntity(CausasDevolucionConcepto.class).list(); t.commit(); if (session.isOpen()) { session.close(); } return lista; } catch (HibernateException he) { LogSistema.guardarlog(this.getClass().getName() + " Method: getCausaDevoConcepEntreId, Excepcion HibernateException: " + he.getMessage()); System.out.println("Error al traer las conceptos de devolucion"); List<CausasDevolucionConcepto> lista = new ArrayList<>(); return lista; } } }