Hibernate LazyInitializationException while using collection in Spring JSP page

后端 未结 3 1454
灰色年华
灰色年华 2020-12-03 19:51

I have entities like this:

@Entity
@Table(name = \"ASSESSMENT\")
public class Assessment {

    //All other fields..

    @OneToMany(fetch = FetchType.LAZY,          


        
3条回答
  •  孤街浪徒
    2020-12-03 20:01

    Loading AssessmentPart from EntityManager will Load Assessment @ManyToOne(fetch = FetchType.EAGER)

    AssessmentPart assessmentPart = //laods a part with entity manager
    Assessment assessment = assessmentPart.getAssessment();
    

    Trying to extract AssessmentParts from assessment wont work since it's not @OneToMany(fetch = FetchType.LAZY) and session is already closed

    model.put("assessmentParts", assessment.getAssessmentParts());
    

    Get list of AssessmentParts by Assessment from EntityManager in new method should solve the problem.

提交回复
热议问题