问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/21405897/fetch-plan-aka-fetch-group-aka-entity-graph-in-querydsl