关于我的问题的简单测试案例的新帖子
当访问属性时,类的惰性DBRef应该触发LazyLoadingInterceptor并为我提供引用背后的真实对象。
public class TestLazyLoadNotWorking {
@Autowired
ARepository aRepository;
@Before
public void setUp(){
aRepository.deleteAll();
}
@Test
public void TestLazyLoadNotWorking(){
A a1 = new A("a1");
A a2 = new A("a2");
a1.a = a2;
aRepository.save(a1);
aRepository.save(a2);
aRepository.findById("1").ifPresent(a -> assertThat(a.a.a_property).isNotNull());
}
}
@Document
public class A {
private static int counter = 0;
@Id
String id = Integer.toString(++counter);
@DBRef(lazy = true)
public A a;
public String a_property;
public A(String a_property){ this.a_property = a_property;}
}