Spring Data JPA And NamedEntityGraphs

前端 未结 5 622
挽巷
挽巷 2020-11-28 04:44

currently I am wrestling with being able to fetch only the data I need. The findAll() method needs to fetch data dependant on where its getting called. I do not want to end

5条回答
  •  春和景丽
    2020-11-28 05:32

    Can you try create EntiyGraph name with child that you will request and give same name to the find all method. Ex:

    @EntityGraph(value = "fetch.Profile.Address.record", type = EntityGraphType.LOAD)
     Employee getProfileAddressRecordById(long id);
    

    For your case:

    @NamedEntityGraph(name="all.Customer.handling_employee.genre", attributeNodes = {
            @NamedAttributeNode("customer"),
            @NamedAttributeNode("handling_employee"),
            @NamedAttributeNode("genre")
    })
    

    method name in repository

    @EntityGraph(value = "all.Customer.handling_employee.genre" , type=EntityGraphType.FETCH)
     findAllCustomerHandlingEmployeeGenre
    

    This way you can keep track of different findAll methods.

提交回复
热议问题