Spring Data JPA Specification to Select Specific Columns

前端 未结 3 1996
遇见更好的自我
遇见更好的自我 2020-12-11 02:08

We can select specific columns by writing custom @Query methods in our Repository Interface. However, I don\'t want to write so many methods for different properties.

<
3条回答
  •  不知归路
    2020-12-11 02:34

    The current spring data jpa specification executor is limited to criteria in the where clause, so you can't change the selected columns, it's implicitely limited to full entities only (take a look at JpaSpecificationExecutor interface documentation). You'll have to go with a custom repository implementation, or move to named queries-

    Spring Data JPA and Querydsl to fetch subset of columns using bean/constructor projection

提交回复
热议问题