Spring JPA native query with Projection gives “ConverterNotFoundException”

后端 未结 5 890
遇见更好的自我
遇见更好的自我 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:17

    @Query(value = "select  isler.saat_dilimi as SAAT, isler.deger as DEGER from isler where isler.id=:id", nativeQuery = true) 
    List getById(@Param("id") Long id);
    
    
    public interface Period{
        Long getDEGER(); 
    
        Long getSAAT();
    
    }
    

    as seen in the example code for native query given above, cast return values to any value like as "SAAT", "DEGER" and then define interface "period" which have getDEGER() and getSAAT(). Even if I have not understand why parameter after get must be uppercase, in lowercase scenario it didn't work properly. ie. interface with getDeger(), getSaat() does not work properly in my case.

提交回复
热议问题