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.mgp.dao; import com.mgp.model.Equipe; import java.util.List; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.springframework.beans.factory.annotation.Autowired; /** * * @author daniel */ public class EquipeDaoImpl implements EquipeDao { @Autowired SessionFactory sessionFactory; Session session = null; Transaction tx = null; @Override public Boolean addEntity(Equipe equipe) throws Exception { session = sessionFactory.openSession(); tx = session.beginTransaction(); session.save(equipe); tx.commit(); session.close(); return false; } @Override public Equipe getEntityById(int idEquipe) throws Exception { session = sessionFactory.openSession(); Equipe equipe = (Equipe) session.load(Equipe.class, new Long(idEquipe)); tx = session.getTransaction(); session.beginTransaction(); tx.commit(); session.close(); return equipe; } @SuppressWarnings("unchecked") @Override public List<Equipe> getEntityList() throws Exception { session = sessionFactory.openSession(); tx = session.beginTransaction(); List<Equipe> equipeList = session.createCriteria(Equipe.class).list(); tx.commit(); session.close(); return equipeList; } @Override public boolean deleteEntity(int idEquipe) throws Exception { session = sessionFactory.openSession(); Object o = session.load(Equipe.class, idEquipe); tx = session.getTransaction(); session.beginTransaction(); session.delete(o); tx.commit(); return false; } }