How can a child entity reference return a LazyInitializationException in an app using OSIV approach (Open Session In View)?
The session seems open immediately before the child开发者_如何转开发 objects are referenced, but there is no record of the specific child object set (even though other child objects are included) in the session's persistence context map of collections (org.hibernate.engineStatefulPersistenceContext.collectionEntries).
The relationship between the parent and child entity is defined by the following:
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@ManyToMany
@JoinTable(name="rt_vacancy_check",
joinColumns = @JoinColumn(name="vacancy_id"),
inverseJoinColumns = @JoinColumn(name="check_name")
)
@BatchSize(size = 10)
private Set<PreEmployCheck> preEmployChecks = new HashSet<PreEmployCheck>();
What possible reasons could there be for this to trigger a LazyInitializationException?
Is it possible that the parent was fetched using a Hibernate session, passed over several requests (in application or session scope) and then used with another Hibernate session?
OSIV uses a threadlocal Hibernate session and different requests can (and usually do) end up using different Hibernate sessions.
精彩评论