I'm trying to put the result of a native query into a projection. But the query result values do not seem to be set to the proper fields in the projection object.
My native query is something like this:
@Query(value = "select p.siteId,"
+ " sum(case when p.arrivalDate = :date then 1 else 0 end) as arrivalTotal "
+ " sum(case when p.departureDate = :date then 1 else 0 end) as departureTotal "
+ " from product p "
+ " where p.collectionSite = :siteId"
+ " and (p.arrivalDate = :date or p.departureDate = :date", nativeQuery = true)
List<DeliverySummary> getDeliverySummary(@Param("siteId") String siteId,
@Param("date") String date);
My projection class is:
public interface DeliverySummary {
String getSiteId();
String getArrivalTotal();
String getDepartureTotal();
}
The results would return like:
siteId = 5 (when actual is site1)
arrivalTotal = "site1" (when actual is 2)
departureTotal = 2 (when actual is 5)
I suspect the issue is because the fields in the projection object are not native fields of the table (and entity), which are sums. Is there a way to set this correctly? TIA