code: @Transactional
      public E findUniqueOrNone(E entity, SearchParameters sp) {
          // this code is an optimization to prevent using a count
          sp.setFirst(0);
          sp.setMaxResults(2);
          List<E> results = find(entity, sp);
  
          if (results == null || results.isEmpty()) {
              return null;
          } else if (results.size() > 1) {
              throw new NonUniqueResultException("Developper: You expected 1 result but we found more ! sample: " + entity);
          } else {
              return results.iterator().next();
          }
      }
docs: /*
  We request at most 2, if there's more than one then we throw a {@link javax.persistence.NonUniqueResultException}
  
  @throws javax.persistence.NonUniqueResultException