title: Check if transaction in hibernate successful
body: <p>I am developing an application using hibernate and I save <code>Entities</code> as usual inside <code>hibernate</code> transactions. I want to 'get Feedback' from a transaction if it has completed sucessfully or not and according to that to excecute next code. Here is the trivial method I use to update the entity:</p>
  
  <pre><code>public boolean updateDepartment(Department s) {
          Session session = HibernateUtil.getSessionFactory().getCurrentSession();
          Transaction tx = HibernateUtil.getTransaction(session);
          boolean success = false;
          try 
          {
              tx.begin();
              session.update(s);
              tx.commit();
              success = true;
          } 
          catch (Exception e) 
          {
              tx.rollback();
              e.printStackTrace();
              success = false;
          }
  
          return success;
      }
  </code></pre>
  
  <p>Invocation of the method from other code:</p>
  
  <pre><code>boolean b = dao.updateDepartment(d);
  if(b)
  {
   doStuff();
  }
  else
  {
   showMessage("Save not usccessful. Try again");
  }
  </code></pre>
  
  <p>My question is whether this approach with the <code>boolean</code> variable is the optimal way, or could it be carried out in a better way. If my approach is OK, would it be better if the <code>return</code> statement would be surrounded with <code>finally</code>?     </p>