SpringData: filtering fields of Entity in Repository My entity is Office. In office repository I would like to find all office Addresses:  

  default List&lt;Address&gt; findOfficeLocations() {
    Iterable&lt;Office&gt; offices = findAll();
    return StreamSupport.stream(offices.spliterator(), false)
        .map(Office::getOfficeLocation).distinct().collect(Collectors.toList());
  }


Is it good practice or better to do it in the Service?
I think that this is not a good practice, but it still may be acceptable in some situations.

The reasons to avoid this:

1) default methods are not intended to introduce new functionality, but rather to provide backwards compatibility for older APIs. The official tutorial says:


  Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces.


2) It looks like you are using JPA. In a Spring repository, you can achieve the same result by using @Query, without detailing the implementation:

@Query("SELECT DISTINCT ol.addresses FROM OfficeLocation ol ...") // TODO complete the HQL
List&lt;Address&gt; findOfficeLocations();


3) If it cannot be done with a query, you are right, a better place for it is a service.