Fetch plan aka. fetch group aka. entity graph in QueryDSL

ぃ、小莉子 提交于 2019-12-11 10:18:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!