Search in sources :

Example 1 with EntityGraph

use of javax.persistence.EntityGraph in project hibernate-orm by hibernate.

the class NamedEntityGraphsTest method testIt.

@Test
public void testIt() {
    EntityGraph graph = getOrCreateEntityManager().getEntityGraph("abc");
    assertNotNull(graph);
    graph = getOrCreateEntityManager().getEntityGraph("xyz");
    assertNotNull(graph);
}
Also used : EntityGraph(javax.persistence.EntityGraph) Test(org.junit.Test)

Example 2 with EntityGraph

use of javax.persistence.EntityGraph in project hibernate-orm by hibernate.

the class SubgraphOrmNamedEntityGraphTest method testSubgraphsAreLoadededFromOrmXml.

@Test
@TestForIssue(jiraKey = "HHH-10633")
public void testSubgraphsAreLoadededFromOrmXml() throws Exception {
    EntityManager entityManager = getOrCreateEntityManager();
    List<EntityGraph<? super Book>> lneg = entityManager.getEntityGraphs(Book.class);
    assertNotNull(lneg);
    Assert.assertEquals(2, lneg.size());
    for (EntityGraph<? super Book> neg : lneg) {
        if (neg.getName().equalsIgnoreCase("full")) {
            assertNotNull(neg.getAttributeNodes());
            for (AttributeNode<?> n : neg.getAttributeNodes()) {
                if (n.getAttributeName().equalsIgnoreCase("authors")) {
                    Assert.assertEquals(1, n.getSubgraphs().size());
                    java.util.List<javax.persistence.AttributeNode<?>> attributeNodes = n.getSubgraphs().get(Author.class).getAttributeNodes();
                    assertNotNull("Subgraph attributes missing", attributeNodes);
                    Assert.assertEquals("Subgraph wrong number of attributes ", 3, attributeNodes.size());
                }
            }
        }
    }
    entityManager.close();
}
Also used : EntityGraph(javax.persistence.EntityGraph) EntityManager(javax.persistence.EntityManager) AttributeNode(javax.persistence.AttributeNode) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with EntityGraph

use of javax.persistence.EntityGraph in project hibernate-orm by hibernate.

the class SessionImpl method createEntityGraph.

@Override
public EntityGraph<?> createEntityGraph(String graphName) {
    checkOpen();
    final EntityGraph named = getEntityManagerFactory().findEntityGraphByName(graphName);
    if (named == null) {
        return null;
    }
    if (EntityGraphImplementor.class.isInstance(named)) {
        return ((EntityGraphImplementor) named).makeMutableCopy();
    } else {
        return named;
    }
}
Also used : EntityGraph(javax.persistence.EntityGraph) EntityGraphImplementor(org.hibernate.graph.spi.EntityGraphImplementor)

Example 4 with EntityGraph

use of javax.persistence.EntityGraph in project hibernate-orm by hibernate.

the class SessionImpl method getEntityGraph.

@Override
@SuppressWarnings("unchecked")
public EntityGraph<?> getEntityGraph(String graphName) {
    checkOpen();
    final EntityGraph named = getEntityManagerFactory().findEntityGraphByName(graphName);
    if (named == null) {
        throw new IllegalArgumentException("Could not locate EntityGraph with given name : " + graphName);
    }
    return named;
}
Also used : EntityGraph(javax.persistence.EntityGraph)

Example 5 with EntityGraph

use of javax.persistence.EntityGraph in project hibernate-orm by hibernate.

the class EntityGraphLoadPlanBuilderTest method testEmbeddedCollection.

@Test
public void testEmbeddedCollection() {
    EntityManager em = getOrCreateEntityManager();
    EntityGraph eg = em.createEntityGraph(ExpressCompany.class);
    eg.addAttributeNodes("shipAddresses");
    // WTF name!!!
    LoadPlan loadLoadPlan = buildLoadPlan(eg, Mode.LOAD, ExpressCompany.class);
    LoadPlanTreePrinter.INSTANCE.logTree(loadLoadPlan, new AliasResolutionContextImpl(sfi()));
    QuerySpace querySpace = loadLoadPlan.getQuerySpaces().getRootQuerySpaces().iterator().next();
    Iterator<Join> iterator = querySpace.getJoins().iterator();
    assertTrue(iterator.hasNext());
    Join collectionJoin = iterator.next();
    assertEquals(QuerySpace.Disposition.COLLECTION, collectionJoin.getRightHandSide().getDisposition());
    assertFalse(iterator.hasNext());
    iterator = collectionJoin.getRightHandSide().getJoins().iterator();
    assertTrue(iterator.hasNext());
    Join collectionElementJoin = iterator.next();
    assertFalse(iterator.hasNext());
    assertEquals(QuerySpace.Disposition.COMPOSITE, collectionElementJoin.getRightHandSide().getDisposition());
    iterator = collectionElementJoin.getRightHandSide().getJoins().iterator();
    assertTrue(iterator.hasNext());
    Join countryJoin = iterator.next();
    assertFalse(iterator.hasNext());
    assertEquals(QuerySpace.Disposition.ENTITY, countryJoin.getRightHandSide().getDisposition());
    // ----------------------------------------------------------------
    LoadPlan fetchLoadPlan = buildLoadPlan(eg, Mode.FETCH, ExpressCompany.class);
    LoadPlanTreePrinter.INSTANCE.logTree(fetchLoadPlan, new AliasResolutionContextImpl(sfi()));
    querySpace = fetchLoadPlan.getQuerySpaces().getRootQuerySpaces().iterator().next();
    iterator = querySpace.getJoins().iterator();
    assertTrue(iterator.hasNext());
    collectionJoin = iterator.next();
    assertEquals(QuerySpace.Disposition.COLLECTION, collectionJoin.getRightHandSide().getDisposition());
    assertFalse(iterator.hasNext());
    iterator = collectionJoin.getRightHandSide().getJoins().iterator();
    assertTrue(iterator.hasNext());
    collectionElementJoin = iterator.next();
    assertFalse(iterator.hasNext());
    assertEquals(QuerySpace.Disposition.COMPOSITE, collectionElementJoin.getRightHandSide().getDisposition());
    iterator = collectionElementJoin.getRightHandSide().getJoins().iterator();
    assertFalse(iterator.hasNext());
    // ----------------------------------------------------------------
    em.close();
}
Also used : EntityGraph(javax.persistence.EntityGraph) AliasResolutionContextImpl(org.hibernate.loader.plan.exec.internal.AliasResolutionContextImpl) EntityManager(javax.persistence.EntityManager) LoadPlan(org.hibernate.loader.plan.spi.LoadPlan) Join(org.hibernate.loader.plan.spi.Join) QuerySpace(org.hibernate.loader.plan.spi.QuerySpace) Test(org.junit.Test)

Aggregations

EntityGraph (javax.persistence.EntityGraph)13 EntityManager (javax.persistence.EntityManager)8 Test (org.junit.Test)8 AliasResolutionContextImpl (org.hibernate.loader.plan.exec.internal.AliasResolutionContextImpl)4 Join (org.hibernate.loader.plan.spi.Join)4 LoadPlan (org.hibernate.loader.plan.spi.LoadPlan)4 QuerySpace (org.hibernate.loader.plan.spi.QuerySpace)4 AttributeNode (javax.persistence.AttributeNode)2 EntityTransaction (javax.persistence.EntityTransaction)2 PersistenceUnitUtil (javax.persistence.PersistenceUnitUtil)2 Query (javax.persistence.Query)2 JPAEntityGraph (org.datanucleus.api.jpa.JPAEntityGraph)2 JPAQuery (org.datanucleus.api.jpa.JPAQuery)2 GraphBase (org.datanucleus.samples.annotations.entitygraph.GraphBase)2 GraphRelated (org.datanucleus.samples.annotations.entitygraph.GraphRelated)2 EntityGraphImplementor (org.hibernate.graph.spi.EntityGraphImplementor)2 ArrayList (java.util.ArrayList)1 NamedEntityGraph (javax.persistence.NamedEntityGraph)1 TestForIssue (org.hibernate.testing.TestForIssue)1