我正在使用 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;
另一个类是相当通用的,所以我不发布它。我的问题是当我尝试访问它时没有加载列表“类”,该属性仍然是某种代理对象。例子:
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();
}
我考虑了很多选择,但没有办法让它工作......