Spring Data JPA/Hibernate handling associations

后端 未结 1 871
旧巷少年郎
旧巷少年郎 2021-01-28 17:56

I need based on parameter retrieve or not some associations from an entity. In the bellow example I need to get the records list only if a parameter is passed through my api. Ca

相关标签:
1条回答
  • 2021-01-28 18:21

    How about using the base findById to return just the Customer object and have another method findWithRecordsById to return customer+records using @EntityGraph?

    public interface CustomerRepository extends JpaRepository<Customer, UUID>{
    
        @EntityGraph(attributePaths = {"records"})
        Customer findWithRecordsById(UUID id);
    ...
    }
    
    0 讨论(0)
提交回复
热议问题