Questions tagged «entitygraph»

4
JPA继承@EntityGraph包括子类的可选关联
给定以下域模型,我想加载所有Answers,包括其Values和其各自的子孩子,并将其放入中AnswerDTO,然后转换为JSON。我有一个可行的解决方案,但它遇到了N + 1问题,我想通过使用ad-hoc摆脱它@EntityGraph。所有关联都已配置LAZY。 @Query("SELECT a FROM Answer a") @EntityGraph(attributePaths = {"value"}) public List<Answer> findAll(); 使用的ad-hoc @EntityGraph对Repository方法我可以确保值是预取的,以防止N + 1上的Answer->Value相关性。虽然我的结果还不错,但是还有一个N + 1问题,因为延迟加载s 的selected关联MCValue。 使用这个 @EntityGraph(attributePaths = {"value.selected"}) 失败,因为该selected字段当然只是某些Value实体的一部分: Unable to locate Attribute with the the given name [selected] on this ManagedType [x.model.Value]; 我如何告诉JPA仅selected在值是a的情况下才尝试获取关联MCValue?我需要类似的东西optionalAttributePaths。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.