How to use projections and specifications with spring data jpa?

前端 未结 6 560
执念已碎
执念已碎 2020-12-13 14:53

I\'m not able to use Spring Data JPA projections and specifications together. I have the following setup:

Entity:

@Entity
public cla         


        
6条回答
  •  醉话见心
    2020-12-13 15:12

    I found this https://github.com/pramoth/specification-with-projection and it seems to work which does exactly what you're looking for. I've included it in my own project and so far no problems. Big thanks to Pramoth.

    Basically you extend JpaSpecificationExecutorWithProjection instead of JpaSpecificationExecutor.

    public interface DocumentRepository extends JpaRepository< Country,Long>,JpaSpecificationExecutorWithProjection
    

    and you get findall() method with projections and specifications

     Page findAll(Specification spec, Class projectionClass, Pageable pageable);
    

提交回复
热议问题