title: JPA Returns null when query.getSingleResult() is returned directly
body: <p>I have a very strange issue with hibernate and jpa. Below are two blocks of code:</p>
  
  <pre><code>public Object getObject(Date date) {
      try {
  
          Query query = entityManager
                  .createQuery(
                          "select ob from Object ob where date= :date");
          query.setParameter("date", date);
  
          return (Object)query.getSingleResult();
  
      } catch (EmptyResultDataAccessException e) {
          logger.debug(String.format("No Result found - date[%s]",date));
          return null;
      }
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>public Object getObject(Date date) {
      try {
  
          Query query = entityManager
                  .createQuery(
                          "select ob from Object ob where date= :date");
          query.setParameter("date", date);
  
          Object ret = (Object)query.getSingleResult();
          return ret;
  
  
      } catch (EmptyResultDataAccessException e) {
          logger.debug(String.format("No Result found - date[%s]",date));
          return null;
      }
  }
  </code></pre>
  
  <p>The first generates an EmptyResultDataAccessException every time even given a valid record where the date matches. The second returns a result as expected. Has anyone encountered this? What causes this behavior?</p>
  
  <p>Please assume all other syntatical things are present(a transaction, initialized entitymanager, etc) the only thing that I change is whether the query results are retrieved directly in the return or assigned to a variable first.</p>