title: Transactional CDI bean: How to force transaction rollback
body: <p>I have a @RequestScoped, @Transactional CDI bean injected in my REST interface:</p>
  
  <pre><code>@RequestScoped
  @Transactional
  public class myRestCall
  {
      @Inject
      EntityHandlerService    ehs;        // contains @PersistenceContext
  
      try
      {
         // execute business logic, access DB via ehs (JPA / Hibernate)
      }
      catch(Throwable t)
      {
          // log exception
          // -&gt; rollback transaction
      }
  }
  </code></pre>
  
  <p>Now I like to have a try / catch around the call of the business logic that I can log the exception properly. But I need to rollback the transaction manually, unless I throw the exception again what I do not like. So how can I force the transasction rollback here? I know how to do it, if it would be a EJB: We could do</p>
  
  <pre><code>@Resource
  private SessionContext ctx;     
  </code></pre>
  
  <p>and then </p>
  
  <pre><code>ctx.setRollbackOnly();
  </code></pre>
  
  <p>in the <code>catch</code> close. </p>
  
  <p>However, it <strong>is not</strong> an EJB and I cannot make an EJB out of it due to resource limits.</p>