use of javax.persistence.PersistenceUnitUtil in project javaee7-samples by javaee-samples.
the class EntityGraphTest method testEntityGraphMovieWithActors.
@Test
public void testEntityGraphMovieWithActors() throws Exception {
PersistenceUnitUtil persistenceUnitUtil = entityManager.getEntityManagerFactory().getPersistenceUnitUtil();
List<Movie> listMoviesWithActorsFetch = movieBean.listMovies("javax.persistence.fetchgraph", "movieWithActors");
for (Movie movie : listMoviesWithActorsFetch) {
assertTrue(persistenceUnitUtil.isLoaded(movie, "movieActors"));
assertFalse(movie.getMovieActors().isEmpty());
for (MovieActor movieActor : movie.getMovieActors()) {
assertFalse(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", "movieWithActors");
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()) {
assertFalse(persistenceUnitUtil.isLoaded(movieActor, "movieActorAwards"));
}
assertTrue(persistenceUnitUtil.isLoaded(movie, "movieDirectors"));
assertFalse(persistenceUnitUtil.isLoaded(movie, "movieAwards"));
}
}
use of javax.persistence.PersistenceUnitUtil in project javaee7-samples by javaee-samples.
the class EntityGraphTest method testEntityGraphMovieDefault.
@Test
public void testEntityGraphMovieDefault() throws Exception {
PersistenceUnitUtil persistenceUnitUtil = entityManager.getEntityManagerFactory().getPersistenceUnitUtil();
List<Movie> listMoviesDefaultFetch = movieBean.listMovies();
for (Movie movie : listMoviesDefaultFetch) {
assertFalse(persistenceUnitUtil.isLoaded(movie, "movieActors"));
assertTrue(persistenceUnitUtil.isLoaded(movie, "movieDirectors"));
assertFalse(persistenceUnitUtil.isLoaded(movie, "movieAwards"));
}
}
use of javax.persistence.PersistenceUnitUtil in project javaee7-samples by javaee-samples.
the class EntityGraphTest method testEntityGraphProgrammatically.
@Test
public void testEntityGraphProgrammatically() throws Exception {
PersistenceUnitUtil persistenceUnitUtil = entityManager.getEntityManagerFactory().getPersistenceUnitUtil();
EntityGraph<Movie> fetchAll = entityManager.createEntityGraph(Movie.class);
fetchAll.addSubgraph(Movie_.movieActors);
fetchAll.addSubgraph(Movie_.movieDirectors);
fetchAll.addSubgraph(Movie_.movieAwards);
List<Movie> moviesFetchAll = movieBean.listMovies("javax.persistence.fetchgraph", fetchAll);
for (Movie movie : moviesFetchAll) {
assertTrue(persistenceUnitUtil.isLoaded(movie, "movieActors"));
assertTrue(persistenceUnitUtil.isLoaded(movie, "movieDirectors"));
assertTrue(persistenceUnitUtil.isLoaded(movie, "movieAwards"));
}
}
Aggregations