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 = {

    })
})
posted @ 2017-09-07 14:14  涉谷猫猫  阅读(661)  评论(0编辑  收藏  举报