I have a Spring Data JPA repository interface that looks something like this:
@Repository
public interface DBReportRepository extends JpaRepository
Just had to solve something similar and Patricks answer helped but it can be improved by indicating where to add it.
To to make it appear like the JPA repo returns a map, an improvement would to wrap this up in a default method in the repository interface. Saves you having to perform a stream in all the consuming classes.
@Repository
public interface DBReportRepository extends JpaRepository {
List findAll();
default Map findAllMap() {
return findAll().stream().collect(Collectors.toMap(TransactionModel::getId, v -> v));
}
List findByClientId(Long id);
default Map findByClientIdMap(Long id) {
return findByClientId(id).stream().collect(Collectors.toMap(TransactionModel::getId, v -> v));
}
}