我正在使用Spring + Spring Data MongoDB。 我的模型如下:
@Document(collection = "actors")
public class Actor extends DomainEntity {
private String name;
private String surname;
@DBRef(lazy = true)
private List<Class> classes;
另一个类比较通用,所以我不会发布它。 我的问题是,当我尝试访问列表“classes”时,它没有被加载,该属性仍然是某种代理对象。 例如:
Actor a = actorRepository.findOne(id);
//At this moment classes are a proxy object because of the lazy
//Now I try to load the reference and nothing works
a.getClasses();
a.getClasses().size();
a.getClases().get(0).getAttr();
for(Class g:a.getClasses()){
g.getAttr();
}
我考虑了很多方案,但没有一种能让它正常工作...