Search in sources :

Example 6 with PersistenceUnitUtil

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"));
    }
}
Also used : PersistenceUnitUtil(javax.persistence.PersistenceUnitUtil) Test(org.junit.Test)

Example 7 with PersistenceUnitUtil

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"));
    }
}
Also used : PersistenceUnitUtil(javax.persistence.PersistenceUnitUtil) Test(org.junit.Test)

Example 8 with PersistenceUnitUtil

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"));
    }
}
Also used : PersistenceUnitUtil(javax.persistence.PersistenceUnitUtil) Test(org.junit.Test)

Aggregations

PersistenceUnitUtil (javax.persistence.PersistenceUnitUtil)8 Test (org.junit.Test)8 Statement (java.sql.Statement)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 PersistenceUtil (javax.persistence.PersistenceUtil)1 House (org.apache.deltaspike.data.test.ee7.domain.House)1 Session (org.hibernate.Session)1 SessionFactory (org.hibernate.SessionFactory)1 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)1 InSequence (org.jboss.arquillian.junit.InSequence)1