-
Notifications
You must be signed in to change notification settings - Fork 9
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
Refactor getSingleResult() to getResultList() #536
Comments
What about returning Optionals from the repositories?
would become:
|
You mean returning optionals (your example doesn't do that)? Sure that could be another way. Maybe we have to split up some code into two methods: one method throws NoResultException and the other doesn't but can return null. |
My example covers the resource, not the repsitory - which would (in this case) return an Optional - yes. Yes - we would have to refactor all calls and do the mapping explicitly - but the nice thing is, that the compiler will tell us about the places where we have to do this - compared to runtime exceptions... |
We should refactor code that calls
getSingleResult()
togetResultList()
where the NoResultException is caught and it's ok if there is no result. See https://stackoverflow.com/questions/24045342/why-jpa-uses-javax-persistence-noresultexceptionIf the NoResultException is not caught directly in the method it can unintentionally lead to transaction rollbacks. See: http://glassfish.10926.n7.nabble.com/Unexpected-Behavior-NoResultException-rolls-back-transaction-td20819.html
I'm not sure what the best way to refactor it is:
Today the NoResultException is automatically mapped to a 404. See REST AMW_rest/resources/resources/{resource}/lte/{RL} http 500 instead of 404 #421
The text was updated successfully, but these errors were encountered: