spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
2.93k stars 1.39k forks source link

Update documentation to demonstrate using RepositoryFactoryCustomizer #953

Open spring-projects-issues opened 10 years ago

spring-projects-issues commented 10 years ago

Thomas Darimont opened DATAJPA-562 and commented

A common requirement that users have is to be able to inspect and / or modify objects after they are returned by the EntityManager before they are passed on to the user code. Therefore it would be helpful to have a pluggable way to generically post-process query results, e.g. to automatically detach result entities or do some additional security checks, mask some data etc


Affects: 1.6 GA (Dijkstra)

Issue Links:

Referenced from: pull request https://github.com/spring-projects/spring-data-jpa/pull/99, and commits https://github.com/spring-projects/spring-data-jpa/commit/256978eee64089c41666397efbc51e3abc641090, https://github.com/spring-projects/spring-data-jpa/commit/c0d950cdb78a70981894760c3fbd7c403600df7c, https://github.com/spring-projects/spring-data-jpa/commit/8ee183c79939167aed37cb76dc94388dc89e1c72

2 votes, 6 watchers

spring-projects-issues commented 10 years ago

Oliver Drotbohm commented

What's the purpose of this? The sample implementations look rather artificial and I have a hard time thinking of a real-world use case. So some clarification would be helpful

spring-projects-issues commented 10 years ago

Pedro Robles commented

Hi Oliver,

On one of the projects I'm working at this moment, we store bank accounts encrypted on the db. Hibernate allows to implement it through custom interceptors.

Hope this helps.

spring-projects-issues commented 10 years ago

Oliver Drotbohm commented

The issue is part of an implementation approach for DATAJPA-565. We've identified a few issues with it and it seems that we're likely about to pursue an alternative solution for the problem this particular ticket was actually intended to solve

spring-projects-issues commented 10 years ago

Rob Winch commented

Oliver Drotbohm -

A few concrete use cases we had were:

spring-projects-issues commented 8 years ago

Robin Jonsson commented

Bumping & Voting for this. I can imagen a lot of use cases for an interceptor on a repository level. I think this would be a really kick-ass feature of Spring Data, to intercept entities/model obj, disregarding underlaying storage (JPA, Mongo, etc) before returning to calling class.

Regards

gregturn commented 2 years ago

Post processing results from the EntityManager has huge risks. Due to JPA's proxy-based, mutable nature, masking data values could cause alterations to the database itself on the next commit. It also risks contracts such as return a Page that had 50 elements, but for some reason now has 49 due to security filter.

Instead, this issue can be used to enhance the ref docs showing how users can hook into Spring Data Commons's RepositoryFactoryCustomizer, which affords multiple things including some variants of post processing.