I have a problem with my Query, when the query executes in intellij console with my parameters it works fine and gives output: CAR EARNINGS 5 140 6 100 And that's fine but I need to create a new list of object and send it back to my frontend in json so what I need is to create this list. When my front send start date parameter and end date to controller and call method getStats then it seems like my resuly form query can't be mapped to class EarningStatistics. I really don't know why and I tried a lot of different approaches but without result... Here is my code:
@Query(value = "SELECT car_id as CAR, SUM(r.cost) as EARNINGS from Rent r where r.rent_date BETWEEN ?1 AND ?2 GROUP BY r.car_id", nativeQuery = true)
List<EarningStatistics> getStatistics(String startDate, String endDate);
And class (I tried to rename fields in this class to car_id and cost but without result)
public class EarningStatistics implements Serializable {
public int CAR;
public double EARNINGS;
public int getCAR() {
return CAR;
}
public void setCAR(int CAR) {
this.CAR = CAR;
}
public double getEARNINGS() {
return EARNINGS;
}
public void setEARNINGS(double EARNINGS) {
this.EARNINGS = EARNINGS;
}
public EarningStatistics(int CAR, double EARNINGS) {
this.CAR = CAR;
this.EARNINGS = EARNINGS;
}
}
How should I code this class and name the fields in it?