我正在尝试使用 spring JPA 存储库和实体图加载实体的惰性属性,EntityGraph 不获取动态提供的关系,而是根据实体中为该属性定义的静态获取类型获取属性。
@Repository
@Transactional
public interface SampleRepository extends JpaRepository<Sample,Long> {
@EntityGraph(attributePaths = {"oneToOneLazyRelation1","oneToOneLazyRelation2"})
List<Sample> findAllByCustomer(Customer customer);
}
@Entity
public class Sample {
@id
private Long id;
@OneToOne(cascade = CascadeType.ALL ,fetch=FetchType.LAZY)
@LazyToOne(value = LazyToOneOption.NO_PROXY)
@LazyGroup("oneToOneLazyRelation1")
private OneToOneLazyRelation1 oneToOneLazyRelation1;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@LazyToOne(value = LazyToOneOption.NO_PROXY)
@LazyGroup("oneToOneLazyRelation2")
private OneToOneLazyRelation2 oneToOneLazyRelation2;
}
使用休眠 - 5.2.17.Final , Spring - 4.3.20.RELEASE , Spring data JPA - 1.11.22.RELEASE