Cause: Hibernate loads the associated object in a lazy way and loads it immediately. If the load method is not specified in a multiple-to-one configuration, and a one-to-many configuration specifies lazy loading, the session is closed when the acquisition party is available, and when a multiparty is obtained, it is not possible to obtain multiple information and therefore an error.
Workaround: Change the one-to-many load mode to immediate load and change the load to lazy loading.
Change the one-to-many annotation configuration to resemble the following:
@OneToMany (mappedby= "topicentity", Fetch = Fetchtype.eager)
Public list<answerentity> getanswerlist () {
return answerlist;
}
public void Setanswerlist (list<answerentity> answerlist) {
This.answerlist = answerlist;
}
Change the multiple-to-one annotation configuration to read as follows:
@ManyToOne (Fetch=fetchtype.lazy,optional=false)
@JoinColumn (name= "TopicID")
Public topicentity gettopicentity () {
return topicentity;
}
public void settopicentity (Topicentity topicentity) {
this.topicentity = topicentity;
}
Use hibernate to get multiparty information from one party error: org.hibernate.LazyInitializationException:failed to lazily initialize a collection of role