Spring JPA : Using Specification with Projection

You may probably know that using Specification with Projection is not possible at this moment.

I'll show you how you can easily bypass this problem using the JPA Criteria.

1. Create an extended repository


We begin by creating an extending global repository as follow :




You can find more information here.

2. Add our custom method

In order to limit the fields returned for each item, the consumer of my API must provide the required fields this way: /orders?fields=productId,name,quantity. (Best Practices)

Basically, I'm defining the SELECT clause with the returned fields (cf. getSelections()):



😎Happy coding...


Comments

Popular posts from this blog

Chip input using Reactive Form