title: EntityManager not finding reference acts differently in try catch if calling println
body: <p>I have an endpoint that looks like this:</p>
  <pre><code>@DeleteMapping(&quot;/{id}&quot;)
  public ResponseEntity&lt;Void&gt; deleteScooter(@PathVariable long id) {
      boolean isDeleted = scootersRepository.deleteById(id);
      if (!isDeleted) throw new ResourceNotFoundException(&quot;The scooter could not be found with id: &quot; + id);
      return ResponseEntity.ok().build();
  }
  </code></pre>
  <p>And the relevant deleteById method:</p>
  <pre><code>@Transactional
  @Override
  public boolean deleteById(long id) {
      boolean isDeleted = false;
      try {
          Scooter scooterRef = entityManager.getReference(Scooter.class, id);
          System.out.println(scooterRef); // &lt;--- this line here
          entityManager.remove(scooterRef);
          isDeleted = true;
      } catch (Exception e) {
          // no-op
      }
      return isDeleted;
  }
  </code></pre>
  <p>If I leave the code like it is shown above and make a call to the delete endpoint passing in an <code>unknown id</code> this will throw a <code>resourceNotFoundException</code> (expected behaviour, all good so far)<br><br>
  But if I remove this specific line from the deleteById method:</p>
  <pre><code>System.out.println(scooterRef); // &lt;--- this line here
  </code></pre>
  <p>An <code>internalServerErrorException</code> is thrown instead.</p>
  <p>My question is, what exactly is this <code>println</code> invocation doing? And is there a cleaner solution to execute the expected behaviour of this code without using a <code>println</code>?</p>
  <hr />
  <p><strong>UPDATE:</strong></p>
  <p>The expected behaviour also occurs if I remove the <code>println</code> and try to access one of the attributes inside the reference, like so:</p>
  <pre><code>// System.out.println(scooterRef);
  scooterRef.getMileage(); // &lt;-- ResourceNotFoundException is thrown, good
  </code></pre>
  <p>Now I do vaguely remember that in some cases you need to access the referenced object in some way (e.g. by calling an attribute) to make it load completely or something like that, but I dont remember the exact reasoning anymore.</p>