title: Spring JPA Repository Cannot Catch EntityNotFoundException
body: <p>I want to throw a custom error class when a user searches my repo with an invalid ID.  This should be very straight forward, but I cannot seem to catch any errors thrown by JpaRepository.  I have made several attempts to solve this, but the following is my most straight forward attempt:</p>
  <pre><code>try {
      Object obj = repository.getOne(id)
  }
  catch (EntityNotFoundException e) {
      throw CustomException(&quot;message&quot;);
  }
  </code></pre>
  <p>When running this in a debugger, repository throws the exact exception I am expecting <code>javax.persistence.EntityNotFoundException</code>, but the code simply skips over my catch statement and the function returns with an error.</p>
  <p>I tried using <code>repository.findById(id)</code> with similar results.  I also tried catching <code>Exception</code> and <code>Throwable</code>.  Any ideas?  I will add more information to my post if it ends up my problem is not immediately obvious.</p>