title: How to solve EmptyResultDataAccessException?
body: <p>@Spring: I wrote a Dao which find a id by another id. when it get the data its fine but when not found shows an exception such like this. </p>
  
  <pre><code>org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
  </code></pre>
  
  <h1>Here is the dao:</h1>
  
  <pre><code>public Integer getIdByMerchantId(Integer merchantId) {
          String query = "SELECT id FROM transaction_history WHERE merchant_id=? ";
          try {
              return serviceJdbcTemplate.queryForObject(query, new Object[]{merchantId}, Integer.class);
  
          } catch (EmptyResultDataAccessException e) {
              log.error("Following query execution failed: ");
              log.error(Utils.getLoggerFriendlyQuery(query), merchantId);
              log.error("{} failed for merchant id {}. Error: {}", query, merchantId, e.getLocalizedMessage());
              return null;
          }
      }
  </code></pre>