Question

I was unable to find any way of implementing fetch plans in QueryDSL, and I tried a lot. Can you provide me any hints? Also, do you know any better way of chosing which fields to fetch and which load lazily in different situations? I use batch fetching, therefore I can't use JOIN FETCH.

Was it helpful?

Solution

With an EntityGraph definition like this

@NamedEntityGraph(
    name = "post",
    attributeNodes = {
        @NamedAttributeNode("title"),
        @NamedAttributeNode(value = "comments", subgraph = "comments")
    },
    subgraphs = {
        @NamedSubgraph(
                name = "comments",
                attributeNodes = {
                    @NamedAttributeNode("content")}
        )
    }
)

the EntityGraph instance can be activated like this on the Querydsl query

EntityGraph postGraph = em.getEntityGraph("post");
query.setHint("javax.persistence.fetchgraph", postGraph)

source: http://hantsy.blogspot.fi/2013/12/jpa-21-entity-graph.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top