Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jpa

querydsl

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.

like image 570
Miloš Lukačka Avatar asked Jan 18 '26 14:01

Miloš Lukačka


1 Answers

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

like image 122
Timo Westkämper Avatar answered Jan 20 '26 02:01

Timo Westkämper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!