I have an entity with aggregation information that I am going to receive from database:
class BookStats {
String author
String title
Integer count
}
My question is could I use some complex object in Repository to filter statistic information. Something like that:
@Query(value = "SELECT new com.test.book.BookStats(b.author, b.title, count(b)) from Book b where b.title = :filter.title and b.author= :filter.author")
List<BookStats> calculateBookStats (@Param("filter") Filter filter)
Spring Data JPA allows to use SpEL :
@Query(value = "SELECT new com.test.book.BookStats(b.author, b.title, count(b)) from Book b where b.title = :#{#filter.title} and b.author= :#{#filter.author}")
List<BookStats> calculateBookStats (@Param("filter") Filter filter)
More info here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With