title: How must I handle database and JPA exceptions?
body: <p>Given the method below how should I deal with possible exceptions that may arise? I want to provide feedback at database level and JPA level. When a constraint violation is thrown, I want to know on what field. How would you handle exceptions of this method?</p>
  <pre><code>public static &lt;T&gt; void persist(T entity) {
      try {
          em.getTransaction().begin();
          em.persist(entity);
          em.getTransaction().commit();
      } finally {
          if (em.getTransaction().isActive()) {
              em.getTransaction().rollback();
          }
      }
  }
  </code></pre>