forked from spring-projects/spring-data-jpa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATAJPA-689 - Allow @entitygraph on CrudRepository.findOne(…).
We now honor @entitygraph definitions on CrudRepository.findOne(…) which was previously only the case for methods that created a Query explicitly. Extracted tryGetFetchGraphHints(…) method from tryConfigureFetchGraph(…) method in Jpa21Utils to allow EntityGraph hints to be used in SimpleJpaRepository.findOne(…). Construction of query hints from context information in SimpleJpaRepository is now performed via the getQueryHints(…) method. Adjusted QueryDslJpaRepository to use query hints as well. Added unit and integration tests to verify that @entitygraph information is propagated to findOne executions. Original pull request: spring-projects#137.
- Loading branch information
Showing
8 changed files
with
134 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,12 +48,15 @@ public class EntityGraphRepositoryMethodsIntegrationTests { | |
@Autowired RepositoryMethodsWithEntityGraphConfigJpaRepository repository; | ||
|
||
User tom; | ||
User olli; | ||
Role role; | ||
|
||
@Before | ||
public void setup() { | ||
|
||
tom = new User("Thomas", "Darimont", "[email protected]"); | ||
olli = new User("Oliver", "Gierke", "[email protected]"); | ||
|
||
role = new Role("Developer"); | ||
em.persist(role); | ||
tom.getRoles().add(role); | ||
|
@@ -75,4 +78,25 @@ public void shouldRespectConfiguredJpaEntityGraph() { | |
assertThat(Persistence.getPersistenceUtil().isLoaded(result.get(0).getRoles()), is(true)); | ||
assertThat(result.get(0), is(tom)); | ||
} | ||
|
||
/** | ||
* @see DATAJPA-689 | ||
*/ | ||
@Test | ||
public void shouldRespectConfiguredJpaEntityGraphInFindOne() { | ||
|
||
Assume.assumeTrue(currentEntityManagerIsAJpa21EntityManager(em)); | ||
|
||
olli = repository.save(olli); | ||
tom.getColleagues().add(olli); | ||
tom = repository.save(tom); | ||
|
||
em.flush(); | ||
|
||
User user = repository.findOne(tom.getId()); | ||
|
||
assertThat(user, is(notNullValue())); | ||
assertThat("colleages should be fetched with 'user.detail' fetchgraph", | ||
Persistence.getPersistenceUtil().isLoaded(user.getColleagues()), is(true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.