ebean: Add API findOne() and findOneOrEmpty() which returns Optional

Expected behavior

Returning Java 8 Optional<? extends Model> when using the method findUnique to allow usage of fallback like orElse or orElseGet and avoiding the direct usage of if (x != null)

More information about Optional at Official Java 8 documentation.

Actual behavior

The method findUnique return an instance of the requested model or null.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 16 (15 by maintainers)

Commits related to this issue

Most upvoted comments

How about:

// add to be more consistent with spring data
T findOne()

// add providing optional return 
Optional<T> findOrEmpty()

// existing method, deprecate over time in favor of the above 2
T findUnique()