I am developing a web service using Spring Data Rest.
public interface BookRepository extends PagingAndSortingRepository {
@Override
@
You can use projection in the output of your repo method.
@Projection(name = "BookWithRating", types = { Book.class })
interface BookWithRating {
Float getRating();
Book getBook();
}
@Query("select avg(rl.rating) as rating, b as book from ReadingList rl join rl.book b group by rl.book order by rating desc")
Page<BookWithRating> findAllWithRating(Pageable pageable);
Pay attention to the alias of the output parameters - their names must match the projection getters.
Also you can try to use this technics for enriching a data model (see how to 'annotate exposed properties with @Value using SpEL expressions to expose synthetic properties').