title: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
body: <p>I use Spring and my problem is that I have a code snippet like this:</p>
  
  <pre><code>@Transactional(rollbackFor = Exception.class)
  private void testMethod1() {
      ...
  
      try {
          testMethod2();
      } catch (CustomException e) {
          e.printStackTrace();
      }
      ...
  }
  </code></pre>
  
  <p>and if testMethod2 throws a CustomException I get the following Exception:</p>
  
  <blockquote>
    <p>Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly</p>
  </blockquote>
  
  <p>I tried </p>
  
  <pre><code>@Transactional(rollbackFor = Exception.class, noRollbackFor = CustomException.class)
      private void testMethod1() {}
  </code></pre>
  
  <p>or </p>
  
  <pre><code>@Transactional(noRollbackFor = CustomException.class)
          private void testMethod1() {}
  </code></pre>
  
  <p>but it does not work. Could somebody help me out?</p>
  
  <p>Thank you!</p>