code: @SuppressWarnings("unchecked")
      @Override
      protected K createKey(ResultSet rs) throws SQLException {
          return (columnName == null) ?
                  (K) rs.getObject(columnIndex) :
                  (K) rs.getObject(columnName);
      }
docs: so getObject will return the appropriate type and the cast will succeed.