Skip to content

Instantly share code, notes, and snippets.

@cr0wst
Last active November 8, 2021 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cr0wst/8bdd1704e3eba5ae5a77b6e661de131d to your computer and use it in GitHub Desktop.
Save cr0wst/8bdd1704e3eba5ae5a77b6e661de131d to your computer and use it in GitHub Desktop.
JpaSpecificationRepository Nullable Extension Function
/**
* By default [JpaSpecificationExecutor.findOne] returns an Optional. This extension function wraps it to return a nullable instead.
*/
fun <T> JpaSpecificationExecutor<T>.findOneOrNull(specification: Specification<T>): T? =
findOne(specification)
.orElse(null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment