How to use projections and specifications with spring data jpa?

前端 未结 6 556
执念已碎
执念已碎 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:29

    @esdee: For now, I Created a Custom Repository Implementation where I created a dynamic query where you can create even a native query and map it to a DTO without using projections.

    In order to do this you can see this doc:

    https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.custom-implementations

    Here is a already example:

    Spring Data JPA Custom Repository

    Just keep in mind that if you want to make it pageable, in your Custom Repository you have to create also a method to count the rows, that you want to extract in your customFindAll(parameters). The disadgantage is that I rewrote the specifications in native query. But maybe the custom Implmentation can work also with Specification, let me know if it helps.

    Regards, C

提交回复
热议问题