@Override public List<Categorie> getAllCategories() { sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); List<Categorie> categories = session.createQuery("from Categorie ").list(); session.close(); return categories; }
@Override public Categorie getCategorieByName(long id) { sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); List<Categorie> categories = session.createQuery("from Categorie where id=" + id).list(); session.close(); return categories.get(0); }
@Override public void deleteCategorie(Categorie categorie) { sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); session.beginTransaction(); session.delete(categorie); session.getTransaction().commit(); session.close(); }
@Override public List<Categorie> getCategorieByFamilly(String familly) { sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); List<Categorie> categories = session.createQuery("from Categorie where famille=" + familly).list(); session.close(); return categories; }
@Override public Categorie getCategorieByName(String name) { sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); List<Categorie> categories = session.createQuery("from Categorie where nom='" + name + "'").list(); session.close(); return categories.get(0); }