Skip to content

findById never returns Empty, but throws an exception instead. [DATAJDBC-124] #356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Aug 10, 2017 · 2 comments
Assignees
Labels
type: bug A general bug

Comments

@spring-projects-issues
Copy link

Jens Schauder opened DATAJDBC-124 and commented

I did not completely verify this but I'm under the impression that findById doesn't return Optional.empty but instead throws an exeception instead


Referenced from: pull request #14, and commits ff50ae4, 1d63be8, 2067fb6

@spring-projects-issues
Copy link
Author

Jens Schauder commented

The root problem is that the NamedParameterJdbcTemplate throws an exception on zero results in queryForObject.

I saw two options to fix this:

a) use query instead of queryForObject and basically reimplementing the check for 0/1/N results, already present in NamedParameterJdbcTemplate

b) catch the right exception and convert it to an Optional.empty

I went with the second approach because:

  1. It makes our template behave similar to that of the spring framework
  2. It avoids reimplementing the cardinality check which feels just as ugly as using exceptions for flow control.

@spring-projects-issues
Copy link
Author

Greg Turnquist commented

I agree with your decision, unless something like performance bubbled up as grossly different in this solution

@spring-projects-issues spring-projects-issues added the type: bug A general bug label Dec 31, 2020
denniseffing pushed a commit to denniseffing/spring-data-jdbc that referenced this issue Jan 7, 2021
Use queryForStream for streamed query results. ResultSetExtractor is ignored because it cannot be used together with streams.

Original pull request spring-projects#176
Closes spring-projects#356
denniseffing added a commit to denniseffing/spring-data-jdbc that referenced this issue Jan 7, 2021
Use queryForStream for streamed query results. ResultSetExtractor is ignored because it cannot be used together with streams.

Original pull request spring-projects#176
Closes spring-projects#356
denniseffing added a commit to denniseffing/spring-data-jdbc that referenced this issue Jan 7, 2021
Use queryForStream for streamed query results. ResultSetExtractor is ignored because it cannot be used together with streams.

Original pull request spring-projects#176
Closes spring-projects#356
denniseffing added a commit to denniseffing/spring-data-jdbc that referenced this issue Jun 28, 2021
Use queryForStream for streamed query results. ResultSetExtractor is ignored because it cannot be used together with streams.

Original pull request spring-projects#176
Closes spring-projects#356
denniseffing added a commit to denniseffing/spring-data-jdbc that referenced this issue Jun 28, 2021
Use queryForStream for streamed query results.
ResultSetExtractor is ignored because it cannot be used together with streams.

Closes spring-projects#356
denniseffing added a commit to denniseffing/spring-data-jdbc that referenced this issue Jun 28, 2021
Use queryForStream for streamed query results.
ResultSetExtractor is ignored because it cannot be used together with streams.

Closes spring-projects#356
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants