title: How to get a unique constraint database exception in play framework
body: <p>I am working on play framework using jpa, I have a field with an unique constraint, after "try" to persist an entity with a repeated value, the framework shows an error page like this:</p>
  
  <p><a href="https://i.stack.imgur.com/O0Zl2.png" rel="nofollow noreferrer">error page</a></p>
  
  <p>When I try to catch this exception...</p>
  
  <pre><code>try{
          JPA.em().persist(nArtist);
      }catch(Exception e){
          form.reject("username","user already exist");
          return badRequest(create_artist.render(form));
      }
  </code></pre>
  
  <p>The page still shows the message... ( I tried already with rollback exception ).</p>
  
  <p>Pdta: That JPA.em() is the only time I called the em.</p>