title: Catching EJBTransactionRolledbackException
body: <p>I have problem with understanding the EJBTransactionRolledbackException.</p>
  
  <p>I have entity:</p>
  
  <pre><code>@Entity
  public class MyEntity {
  
      @Id
      @GeneratedValue
      private Long id;
      @Size(max=5)
      private String name;
  //...
  }
  </code></pre>
  
  <p>and repository which is SLSB because of ease of CMT:</p>
  
  <pre><code>@Stateless
  public class ExampleRepository {
      @PersistenceContext
      private EntityManager em;
  
      public void add(MyEntity me) {
          em.persist(me);
      }
  }
  </code></pre>
  
  <p>now I have test Servlet, when I simulate ConstraintViolation (too long name).</p>
  
  <pre><code>@WebServlet("/example")
  public class ExampleServlet extends HttpServlet {
      @Inject
      private ExampleRepository repo;
  
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          MyEntity me = new MyEntity();
          me.setName("TooLongName");
          try {
              repo.add(me);
          } catch(EJBTransactionRolledbackException e) {
              System.out.println("Exception caught");
          }
      }
  }
  </code></pre>
  
  <p>I know that in such scenario EJB container will wrap the ConstraintViolationException so I catch the EJBTransactionRolledbackException instead. The problem is that in the console I can see my message from catch block ("Exception caught") but before that there are tons of exception logs produced (<a href="http://pastebin.com/BBT66RyB" rel="nofollow">link</a>).
  I don't quite understand what happened - is this exception caught or not? How to prevent all these error messages in the console in such simple scenario?</p>