JPA Data Repositories with SqlResultSetMapping and native queries

前端 未结 3 1993
梦如初夏
梦如初夏 2020-12-16 14:19

I was stuck with the following situation:

My entities are related to each other, but in such a way that i could not use JPQL. I was forced to use native SQL. Now I w

3条回答
  •  一生所求
    2020-12-16 14:57

    Add the missing resultClass

    @NamedNativeQuery(name = "findAllDataMapping", resultClass = Entity.class, query="sql")
    

    Or

    @NamedNativeQuery(name = "findAllDataMapping", resultClass = MyVO.class, resultSetMapping ="findAllDataMapping" query = "sql")
    

    and lastly call the query in your repository

    @Query(nativeQuery = true, name = "findAllDataMapping")
    List findAllOfMyVO(@Param("param1") String param1, @Param("param2") String param2);
    

提交回复
热议问题