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.gianburga.servicios.model; import com.gianburga.servicios.bean.Tecnico; import java.util.List; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; /** * * @author gianfranco */ @Repository("tecnicoDAO") public class TecnicoDAOImpl implements TecnicoDAO { @Autowired private SessionFactory mySessionFactory; @Override public List<Tecnico> getAll() { Session session = mySessionFactory.getCurrentSession(); session.beginTransaction(); return session.createQuery("from Tecnico").list(); } @Override public Integer save(Tecnico tecnico) { Session session = mySessionFactory.getCurrentSession(); session.beginTransaction(); session.saveOrUpdate(tecnico); session.getTransaction().commit(); return tecnico.getId(); } @Override public void remove(int id) { Session session = mySessionFactory.getCurrentSession(); session.beginTransaction(); Tecnico tecnico = (Tecnico) session.load(Tecnico.class, id); session.delete(tecnico); session.getTransaction().commit(); } @Override public Tecnico get(int id) { Session session = mySessionFactory.getCurrentSession(); session.beginTransaction(); return (Tecnico) session.load(Tecnico.class, id); } }