public List<Event> list() {
   session = HibernateUtil.getSessionFactory().openSession();
   transaction = session.beginTransaction();
   events = (List<Event>) session.createQuery("from Event").list();
   participationService.setParticipants(events);
   return events;
 }
 public boolean delete(Event event) {
   session = HibernateUtil.getSessionFactory().openSession();
   try {
     transaction = session.beginTransaction();
     try {
       session.delete(event);
       if (!transaction.wasCommitted()) {
         transaction.commit();
       }
       return true;
     } catch (Exception e) {
       transaction.rollback();
       throw e;
     }
   } finally {
     session.close();
   }
 }
 public Event update(Event event) {
   session = HibernateUtil.getSessionFactory().openSession();
   try {
     transaction = session.beginTransaction();
     try {
       session.update(event);
       if (!transaction.wasCommitted()) {
         transaction.commit();
       }
       return event;
     } catch (HibernateException e) {
       e.printStackTrace();
       transaction.rollback();
     }
   } catch (Exception e) {
     transaction.rollback();
   } finally {
     session.close();
   }
   return null;
 }