-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
We should refactor code that calls getSingleResult() to getResultList() 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-noresultexception
If 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:
- Just return null if there is no result
- Can lead to unintended NullPointer exceptions if not carefully refactored.
- In the REST services you have to explicitly check for null and convert that into a 404 response.
- Can still be converted to a runtime exception by services if they can't deal with nulls.
- It has to be check if there is more then one result.
Today the NoResultException is automatically mapped to a 404. See REST AMW_rest/resources/resources/{resource}/lte/{RL} http 500 instead of 404 #421
- Return a custom checked exception. I experimented with this here: https://github.com/liimaorg/liima/compare/getResourceGroupByName_NoResultException
- Exception has to be explicitly declared in method signatures
- Null has to be checked for and converted to an exception
- Can be mapped in REST
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels