Spring Data JPA查询关联数据

1. Query方式
@Query("select s from Store s join fetch s.products where s.user.id = :user_id")

2.@EntityGraph(attributePaths = { "products" })

3. @NamedEntityGraphs({
    @NamedEntityGraph(name="allJoinsButMessages", attributeNodes = {
            @NamedAttributeNode("customer"),
            @NamedAttributeNode("handling_employee"),
            @NamedAttributeNode("genre")
    }),
    @NamedEntityGraph(name="allJoins", attributeNodes = {
            @NamedAttributeNode("customer"),
            @NamedAttributeNode("handling_employee"),
            @NamedAttributeNode("genre"),
            @NamedAttributeNode("complaintMessages")
    }),
    @NamedEntityGraph(name="noJoins", attributeNodes = {

    })
})
原文地址:https://www.cnblogs.com/mkxzy/p/7489455.html