What is difference between creating a SDR Projection and then
(i) Explicitly declaring that in corresponding Repository as in -
@RepositoryRestResource(excerptProjection = UserSummaryProjection.class)
public interface UserRepository extends JpaRepository<User, Integer> { ..
}
(ii) Not explicitly defining Projection in Repository
What I find is that when Projection is explicitly declared in Repository , then that projection is shown for that entity wherever findAll or findByID gets called.
But when it is not declared, then there is an option left to either user / not use them so, by default all fields get shown.
some examples -
I also find that when a projection is defined, then the link disappears. For example - There is UserLanguage and RefLanguage and say, there are 2 repositories UserLanguageRepository and ResfLanguageRepository , then there is also RefLangSummaryProjection
UserLanguage -> ManytoOne -> REfLanguage RefLanguage -> OneToMany -> UserLanguage
So, going to URL /userLanguages or /userLanguages/{id} shows embedded data for RefLanguage with field coming out from RefLangSummaryProjection and link to RefLang is gone. That is probably expected however I dont like the query that is generated for REFLangSummaryProejction which still selects all columns
Projections are basically a two fold thing:
You create projections to enable clients to see different views of a resource. The projections are defined as interfaces, named and then exposed to the client by a request parameter. The client is now able to choose exactly one of the registered projections or free to choose none of them at all.
You can elevate one of the registered projections to become an excerpt projection (hence the attribute name). If declared, it will automatically be used in places where related resources appear in the representation. With the default HAL format this is the case for everything that's rendered in the _embedded
clause.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With