Posts

Showing posts from May, 2019

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...

Spring JPA : test interface-based projection using factory

In this short article, I'll show you how you can easily test a repository method which uses interface-based projection . Our repository: You can use the above method this ways: I use the ProjectionFactory as well as the SpelAwareProxyProjectionFactory for testing ( spring doc ). You must also provide the setters on your interface as follow: Happy reading...