Announcement Announcement Module
No announcement yet.
NamedParameterJdbcTemplate.queryForObject() Exceptions Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • NamedParameterJdbcTemplate.queryForObject() Exceptions

    Looking through some code, I found something like this:
    try {
    product = namedParameterJdbcTemplate.queryForObject(
    query, params, new ProductMapper());
    } catch (EmptyResultDataAccessException e) {
    // Handle

    However, in the API docs, for NamedParameterJdbcTemplate.queryForObject(), it doesn't list EmptyResultDataAccessException as something that is thrown:

    IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row

    So I believe that an EmptyResultDataAccessException would never be thrown, is that correct?
    If so, then the compiler isn't complaining, and I was wondering if in a future release of Spring it would be possible to have some sort of warning displayed.


  • #2
    Use [code ][/code ] tags when posting code. The exceptions are runtime exceptions so they aren't checked by the compiler. If no result is thrown you will get the EmptyResultSet exception (which is a sub class of the IncorrectResultSizeDataAccessException ).


    • #3
      I was thinking there might might be a clever way using annotations, but maybe it's not possible to get a compiler warning.

      I guess it's not that difficult to check the API docs, but what if the queryForObject() method also threw an IncorrectResultSizeDataAccessException. You could then see the subclasses of DataAccessException that were thrown more quickly from the tooltip when highlighting the method in eclipse.