Spring Data JPA only supports EntityGraph through annotations.
Thus, for a repository method, you must select at most one EntityGraph before compilation.
This prevents you from choosing the best EntityGraph considering the runtime context 💔
Thanks to spring-data-jpa-entity-graph, you can choose EntityGraph at runtime!
This choice is elegantly made by passing EntityGraph, as an argument, to any Spring Data JPA repository method 😍
// This will apply 'Product.brand' named EntityGraph to findByLabel
productRepository.findByLabel("foo", EntityGraphs.named("Product.brand"));
// This will apply "product(brand, category, maker(country))" dynamic EntityGraph to findByLabel
productRepository.findByLabel(
"foo",
// ProductEntityGraph was generated at compilation time
ProductEntityGraph.____()
.brand()
.____
.category()
.____
.maker()
.country()
.____
.____()
);
Now run to the documentation !
This library follows the Spring Data JPA versionning semantic.
spring-data-jpa branches | Latest spring-data-jpa-entity-graph version | Documentation |
---|---|---|
2.6.x | 2.6.x documentation | |
2.5.x | 2.5.x documentation | |
2.4.x | 2.4.x documentation | |
2.3.x | 2.3.x documentation | |
2.2.x | 2.2.x documentation | |
2.1.x | 2.1.x documentation | |
2.0.x | 2.0.x documentation | |
1.11.x | 1.11.x documentation | |
1.10.x | 1.10.x documentation |
For example, if you were using spring-data-jpa 2.2.x
in your project, you would need to select any spring-data-jpa-entity-graph 2.2.x
. Thus spring-data-jpa-entity-graph 2.2.8
would be eligible.
You can play with https://github.com/Cosium/spring-data-jpa-entity-graph-sample to see the extension in action in a simple Spring Application.
This talk was given at Paris JUG in January 2019.
The slides are in english.
The video is in french:
This project was created following the discussion in Spring Data Tracker issue DATAJPA-749 - Context enabled JPA 2.1 @EntityGraph .