jpa entitygraph What is the difference if I use addSubgraph instead of addAttributeNodes?

61 Views Asked by At

Halo

the two codes below generate the same query. there doesn't seem to be any difference between the addSubgraph and addAttributeNodes methods... so why do there exist two methods?

        EntityGraph entityGraph = entityManager.createEntityGraph(Academy.class);
        entityGraph.addAttributeNodes("students");
        List<Academy> list = entityManager.createQuery("SELECT a FROM Academy a")
                .setHint("jakarta.persistence.fetchgraph", entityGraph)
                                .getResultList();

and

        EntityGraph entityGraph = entityManager.createEntityGraph(Academy.class);
        entityGraph.addSubgraph("students");
        List<Academy> list = entityManager.createQuery("SELECT a FROM Academy a")
                .setHint("jakarta.persistence.fetchgraph", entityGraph)
                                .getResultList();
0

There are 0 best solutions below