-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Allow programmatic use of entity graphs [DATAJPA-560] #951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thomas Darimont commented Hi Andreas, this would be a valuable feature :) Do you have some concrete examples in mind how you would use such a feature? Cheers, |
Andreas Schilling commented Hi Thomas, yes, using the special parameter would be definitely one of the main usage scenarios and also be consistent with what's already there for the other special types. Regards, Andreas |
liujiong commented please review the PR |
Daniel Frank commented Any news about this issue? |
Oliver Drotbohm commented I just ran across the PR during a review. The PR is not gonna cut it as it removes public API. Also, it doesn't really use the Spring Data means to declare and obtain special parameters. Generally speaking, I'm not too sure I'd like to see this implemented at all. What we'd end up with is store specific API to be exposed through repository methods and thus leaking into clients. This is something you'd like to avoid by all means as the sole purpose of a repository is hiding the actual persistence technology used. Plus, to apply this stuff consistently we'd need to introduce JPA-specific extensions of |
Andreas Schilling commented Oliver, I definitely see your points. Thinking a bit more about it right now, it's not only the leaking but already simply the addition of optional parameters you may or may not need depending on the use case which I wouldn't like to see myself in a codebase :-) |
Jens Schauder commented I think this discussion is done. We even manage to convince the OP ;o) |
Thank you @schauder for pointing me to this existing issue. If possible, I would like this feature to be reexamined. The current alternative consists in adding X methods in the repository saying : findBySomethingAndFetchThis, findBySomethingAndFetchThisAndThat, which is actually equivalent and more verbose. Could you have a look at #2556 ? |
Why not? EntityGraphs of course do what you describe: they provide a persistence technology specific way of defining which parts of an aggregate to load. And, yes, if a client wanted to make programmatic use of them, it can't do so without referring to the concept. That's a problem of entity graphs, but it doesn't mean that it's a good idea to break the abstraction with them. They suffer from more problems even, as persisting the partially loaded aggregates will wipe data if you're not careful. Also, consider that there are way less invasive approaches to the fundamental problem. Using DTO or interface projections, and by that basically introducing a dedicated model for specific read requirements, are a much better way to approach this problem. They're store- and even Spring Data independent, and work consistently across the different data modules. Plus, they clearly separate read models from write ones and do not overload the latter with the former. |
Andreas Schilling opened DATAJPA-560 and commented
For clearly separated (query) use cases having different repository methods with different entity graphs applied is a fine way to control what data is fetched during a query. Then we can give this kind of query a clear name.
With a larger number of graphs or when it should be possible to dynamically decide before a query what graph should be used (e.g. the user may select the amount of detail data she sees) however a programmatic way to apply a graph would be good to keep down the amount of query methods.
This is especially the case if the "base query" stays the same (i.e. no dynamic WHERE or the like).
All this is already possible with Specifications, using entity graphs however would feel more natural and result in less boilerplate code
Affects: 1.6 GA (Dijkstra)
Issue Links:
DATAJPA-1291 Allow findById caller to choose which lazy relations should be fetched
("is depended on by")
DATAJPA-645 Enable JPA 2.1 EntityGraphs to be specified dynamically
("is duplicated by")
DATAJPA-466 Add support for lazy loading configuration via JPA 2.1 fetch-/loadgraph
DATAJPA-696 Support ad-hoc fetch graph configurations on repository methods
Referenced from: pull request #112
4 votes, 8 watchers
The text was updated successfully, but these errors were encountered: