@Test
public void testEntityGraphMovieWithActorsAndAwards() throws Exception {
PersistenceUnitUtil persistenceUnitUtil = entityManager.getEntityManagerFactory().getPersistenceUnitUtil();
List<Movie> listMoviesWithActorsFetch =
movieBean.listMovies("javax.persistence.fetchgraph", "movieWithActorsAndAwards");
for (Movie movie : listMoviesWithActorsFetch) {
assertTrue(persistenceUnitUtil.isLoaded(movie, "movieActors"));
assertFalse(movie.getMovieActors().isEmpty());
for (MovieActor movieActor : movie.getMovieActors()) {
assertTrue(persistenceUnitUtil.isLoaded(movieActor, "movieActorAwards") ||
!persistenceUnitUtil.isLoaded(movieActor, "movieActorAwards"));
}
// https://hibernate.atlassian.net/browse/HHH-8776
// The specification states that by using fetchgraph, attributes should stay unloaded even if defined as
// EAGER (movieDirectors), but specification also states that the persistence provider is allowed to fetch
// additional state.
assertTrue(persistenceUnitUtil.isLoaded(movie, "movieDirectors") ||
!persistenceUnitUtil.isLoaded(movie, "movieDirectors"));
assertFalse(persistenceUnitUtil.isLoaded(movie, "movieAwards"));
}
List<Movie> listMoviesWithActorsLoad =
movieBean.listMovies("javax.persistence.loadgraph", "movieWithActorsAndAwards");
for (Movie movie : listMoviesWithActorsLoad) {
// https://java.net/jira/browse/GLASSFISH-21200
// Glassfish is not processing "javax.persistence.loadgraph".
assertTrue(persistenceUnitUtil.isLoaded(movie, "movieActors"));
assertFalse(movie.getMovieActors().isEmpty());
for (MovieActor movieActor : movie.getMovieActors()) {
assertTrue(persistenceUnitUtil.isLoaded(movieActor, "movieActorAwards"));
}
assertTrue(persistenceUnitUtil.isLoaded(movie, "movieDirectors"));
assertFalse(persistenceUnitUtil.isLoaded(movie, "movieAwards"));
}
}