Spring Data JPA. How to get only a list of IDs from findAll() method

后端 未结 4 1406
小蘑菇
小蘑菇 2020-12-13 18:16

I have a very complicated model. Entity has a lot relationship and so on.

I try to use Spring Data JPA and I prepared a repository.

but when I invoke a met

4条回答
  •  时光取名叫无心
    2020-12-13 18:48

    Why not using the @Query annotation?

    @Query("select p.id from #{#entityName} p")
    List getAllIds();
    

    The only disadvantage I see is when the attribute id changes, but since this is a very common name and unlikely to change (id = primary key), this should be ok.

提交回复
热议问题