zp26
zp26

Reputation: 1527

Problem with Iteration and Set

I have a problem with my program.

When i run the program:

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>");
   }
}

The error is:

failed to lazily initialize a collection of role: lesson.domain.CourseMaterial.lectures, no session or session was closed

There are a problem in my code?

Thanks

Upvotes: 0

Views: 56

Answers (1)

Aravind Yarram
Aravind Yarram

Reputation: 80194

Seems like you are using ORM in your application and configured lectures to be loaded lazily. You can either change the config to load them eagerly or iterate the lectures in a transaction.

Upvotes: 2

Related Questions