Reputation: 1206
Spring Data JPA can sum colomn using specifications. But does it have any way to sum an entity column using method name resolving? Let's say I want a method sumCreditAmount to sum column with specific name, just like a method findByCreditAmount to fetch all entities with a specific creditAmount.
Upvotes: 5
Views: 12230
Reputation: 4309
Spring Data JPA does not provide inbuilt support for aggregate methods. But you can get sum by using:
@Query("SELECT sum(e.creditAmount) from Entity e")
int sumCreditAmount();
You need to declare the above method in your repository class.
Upvotes: 11