[
https://issues.apache.org/jira/browse/DELTASPIKE-421?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13784879#comment-13784879
]
Thomas Hug commented on DELTASPIKE-421:
---------------------------------------
Sounds good to me too. I guess we should then also have the same options for
- @Query (e.g. with result = ResultType.OPTIONAL)
- QueryResult<E> (.getOptionalResult() / .getAnyResult())
The default behavior should still be aligned with JPA I think.
> Find zero or one
> ----------------
>
> Key: DELTASPIKE-421
> URL: https://issues.apache.org/jira/browse/DELTASPIKE-421
> Project: DeltaSpike
> Issue Type: New Feature
> Components: Data-Module
> Affects Versions: 0.5
> Reporter: Harald Wellmann
>
> At the moment,
> E findByFoo(T foo)
> behaves like Query.getSingleResult(), i.e. it throws an exception if there is
> no result or more than one result.
> Dealing with these exceptions is inconvenient when the semantics required by
> the user is "find zero or one" or "find any one".
> These cases should be supported by
> E findOptionalByFoo(T foo)
> which
> - returns null when there is no result
> - returns the single result when there is exactly one result
> - throws NonUniqueResultException when there is more than one result
> and
> E findAnyByFoo(T foo)
> which
> - returns null when there is no result
> - returns the first result otherwise
--
This message was sent by Atlassian JIRA
(v6.1#6144)