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);
}
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();
}
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;
}
}
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;
}
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();
}
Aggregations