JPA inheritance @EntityGraph include optional associations of subclasses
问题 Given the following domain model, I want to load all Answer s including their Value s and their respective sub-children and put it in an AnswerDTO to then convert to JSON. I have a working solution but it suffers from the N+1 problem that I want to get rid of by using an ad-hoc @EntityGraph . All associations are configured LAZY . @Query("SELECT a FROM Answer a") @EntityGraph(attributePaths = {"value"}) public List<Answer> findAll(); Using an ad-hoc @EntityGraph on the Repository method I can