我的程序有问题。
当我运行程序时:
CourseMaterial crsmPrint = new CourseMaterial();
Iterator<CourseMaterial> itPrint = trs.getAllTrainerCourseMaterial(Integer.parseInt(request.getSession().getAttribute("id").toString())).iterator();
while (itPrint.hasNext()){
crsmPrint = itPrint.next();
Lecture lctPrint = new Lecture();
Iterator<Lecture> itLctPrint = trs.getAllLecture(crsmPrint.getId()).iterator();
while(itLctPrint.hasNext()){
lctPrint = itLctPrint.next();
out.print("<option>"+lctPrint.getId()+"</option>");
}
}
错误是:
failed to lazily initialize a collection of role: lesson.domain.CourseMaterial.lectures, no session or session was closed
我的代码有问题吗?
由于
答案 0 :(得分:2)
似乎您在应用程序中使用ORM并配置讲座以便懒惰加载。您可以更改配置以急切加载它们,也可以在事务中迭代讲座。