How do I fetch list of long ids using JpaRepository?

71 Views Asked by At

I want to fetch List of ids instead of List. How should I define it using JpaRepository syntax? The same code, but I want something like List<Long> ids....

Is there a way to do it using JpaRepository without using @Query?

List<Education> findByUserId(Long userId);
1

There are 1 best solutions below

1
On

I don't think this is possible. As a workaround you can use a Projection containing only the id.

public interface EducationIdProjection {

  Long getId();
}

The repository method:

List<EducationIdProjection> findByUserId(Long userId);