Search in sources :

Example 1 with EntityGraph

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

the class BasicOrmNamedEntityGraphTest method testIt.

@Test
void testIt(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        EntityManager em = session.unwrap(EntityManager.class);
        EntityGraph graph = em.getEntityGraph("Person");
        assertThat(graph, notNullValue());
    });
}
Also used : EntityGraph(jakarta.persistence.EntityGraph) EntityManager(jakarta.persistence.EntityManager) Test(org.junit.jupiter.api.Test)

Example 2 with EntityGraph

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

the class SubgraphOrmNamedEntityGraphTest method testSubgraphsAreLoadedFromOrmXml.

@Test
@TestForIssue(jiraKey = "HHH-10633")
void testSubgraphsAreLoadedFromOrmXml(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        EntityManager entityManager = session.unwrap(EntityManager.class);
        List<EntityGraph<? super Book>> lneg = entityManager.getEntityGraphs(Book.class);
        assertThat(lneg, notNullValue());
        assertThat(lneg, hasSize(2));
        for (EntityGraph<? super Book> neg : lneg) {
            if (neg.getName().equalsIgnoreCase("full")) {
                assertThat(neg.getAttributeNodes(), notNullValue());
                for (AttributeNode<?> n : neg.getAttributeNodes()) {
                    if (n.getAttributeName().equalsIgnoreCase("authors")) {
                        assertThat(n.getSubgraphs().entrySet(), hasSize(1));
                        List<AttributeNode<?>> attributeNodes = n.getSubgraphs().get(Author.class).getAttributeNodes();
                        assertThat(attributeNodes, notNullValue());
                        assertThat(attributeNodes, hasSize(3));
                    }
                }
            }
        }
    });
}
Also used : EntityGraph(jakarta.persistence.EntityGraph) EntityManager(jakarta.persistence.EntityManager) AttributeNode(jakarta.persistence.AttributeNode) Test(org.junit.jupiter.api.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with EntityGraph

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

the class BasicAnnNamedEntityGraphTest method testIt.

@Test
void testIt(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        EntityManager em = session.unwrap(EntityManager.class);
        EntityGraph graph = em.getEntityGraph("Person");
        assertThat(graph, notNullValue());
    });
}
Also used : EntityGraph(jakarta.persistence.EntityGraph) EntityManager(jakarta.persistence.EntityManager) Test(org.junit.jupiter.api.Test)

Example 4 with EntityGraph

use of jakarta.persistence.EntityGraph in project eclipselink by eclipse-ee4j.

the class EntityManagerImpl method getEntityGraphs.

@Override
public <T> List<EntityGraph<? super T>> getEntityGraphs(Class<T> entityClass) {
    ClassDescriptor descriptor = getAbstractSession().getDescriptor(entityClass);
    if (descriptor == null || descriptor.isAggregateDescriptor()) {
        throw new IllegalArgumentException(ExceptionLocalization.buildMessage("unknown_bean_class", new Object[] { entityClass.getName() }));
    }
    List<EntityGraph<? super T>> result = new ArrayList<EntityGraph<? super T>>();
    for (AttributeGroup group : descriptor.getAttributeGroups().values()) {
        result.add(new EntityGraphImpl<>(group));
    }
    if (descriptor.hasInheritance()) {
        while (descriptor.getInheritancePolicy().getParentDescriptor() != null) {
            descriptor = descriptor.getInheritancePolicy().getParentDescriptor();
            for (AttributeGroup group : descriptor.getAttributeGroups().values()) {
                result.add(new EntityGraphImpl<>(group));
            }
        }
    }
    return result;
}
Also used : EntityGraph(jakarta.persistence.EntityGraph) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ArrayList(java.util.ArrayList) AttributeGroup(org.eclipse.persistence.queries.AttributeGroup)

Aggregations

EntityGraph (jakarta.persistence.EntityGraph)4 EntityManager (jakarta.persistence.EntityManager)3 Test (org.junit.jupiter.api.Test)3 AttributeNode (jakarta.persistence.AttributeNode)1 ArrayList (java.util.ArrayList)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 AttributeGroup (org.eclipse.persistence.queries.AttributeGroup)1 TestForIssue (org.hibernate.testing.TestForIssue)1