Spring JPA native query with Projection gives “ConverterNotFoundException”

后端 未结 5 892
遇见更好的自我
遇见更好的自我 2020-12-10 11:22

I\'m using Spring JPA and I need to have a native query. With that query, I need to get only two fields from the table, so I\'m trying to use Projections. It isn\'t working

5条回答
  •  醉酒成梦
    2020-12-10 12:05

    You can return list of Object Array (List) as return type of the native query method in repository class.

    @Query(
                value = "SELECT [type],sum([cost]),[currency] FROM [CostDetails] " +
                        "where product_id = ? group by [type],[currency] ",
                nativeQuery = true
        )
        public List getCostDetailsByProduct(Long productId);
    
    for(Object[] obj : objectList){
         String type = (String) obj[0];
         Double cost = (Double) obj[1];
         String currency = (String) obj[2];
         }
    

提交回复
热议问题