I am developing a web service using Spring Data Rest.
public interface BookRepository extends PagingAndSortingRepository<Book, Long> {
@Override
@Query("select avg(rl.rating) as rating, b from ReadingList rl join rl.book b group by rl.book order by rating desc")
Page<Book> findAll(Pageable pageable);
}
When I select in JPQL as above, 'avg (rl.rating) as rating' column does not have the name like the image below.
rating: 4.0
I would like to do this service.
In addition, the full source is in github. https://github.com/ohgamja3/readinglist-rest-server/
I would like help with this issue. Thanks for reading.
You can use projection in the output of your repo method.
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').