Skip to content
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

findBy in JpaRepository throws EmptyResultException instead of returning null #1323

Closed
weaser opened this issue Feb 5, 2022 · 5 comments
Closed
Labels
closed: notabug The issue is not a bug

Comments

@weaser
Copy link

weaser commented Feb 5, 2022

Expected Behavior

I expect a CRUD method like findByEmail in an JpaRepository to return null, when no entry is found in the mysql database.

User findByEmail(String email);

Actual Behaviour

User user = userRepository.findByEmail("xxx@example.com");
results in an io.micronaut.data.exceptions.EmptyResultException

Checking for null if(user==null) is not reached.

Steps To Reproduce

Executing a CRUD method in an JpaRepository with no expected results from the db table should reproduce it.

Environment Information

  • Windows 10
  • Micronaut version 3.2.0
  • Java version 11
  • mysql 8.0.20 in docker

Example Application

https://github.com/weaser/jpa-test

Version

3.2.0

@graemerocher
Copy link
Contributor

You have to annotate the return type with Nullable

@weaser
Copy link
Author

weaser commented Feb 6, 2022 via email

@weaser weaser closed this as completed Feb 6, 2022
@weaser
Copy link
Author

weaser commented Feb 6, 2022

@graemerocher
The Nullable solution did not work for me, at least I could not figure it out.
I do not know if the following solution is optimal, but it works for me.

Using Optional<User> findByEmail(String email); in the repository
and then after the call checking user.isEmpty()

@dstepanov dstepanov reopened this Feb 7, 2022
dstepanov added a commit that referenced this issue Feb 21, 2022
@dstepanov
Copy link
Contributor

@weaser I have added a test case that shows how to avoid ERE #1349

dstepanov added a commit that referenced this issue Feb 21, 2022
@dstepanov
Copy link
Contributor

Closing it as non-issue.

@dstepanov dstepanov added the closed: notabug The issue is not a bug label Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed: notabug The issue is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants