获取计划又名.取组也称.QueryDSL中的实体图

Mil*_*čka 1 java jpa querydsl

我无法在QueryDSL中找到任何实现获取计划的方法,我尝试了很多.你能给我任何提示吗?另外,你知道更好的方法来选择要获取哪些字段以及在不同情况下懒散加载哪些字段?我使用批量提取,因此我不能使用JOIN FETCH.

Tim*_*per 6

使用像这样的EntityGraph定义

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

EntityGraph实例可以这样被激活的Querydsl查询

EntityGraph postGraph = em.getEntityGraph("post");
query.setHint("javax.persistence.fetchgraph", postGraph)
Run Code Online (Sandbox Code Playgroud)

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

  • 我想这是对QueryDSL的一个很好的补充,它允许以流畅的方式实现实体图的*定义*.JPA中有`EntityGraph` API允许这样做,但它不能流利/ DSL-ish. (2认同)