Synopsis:Hello all, I am at a total loss here: I have an entity (say A) with several One-to-many relationships (all with FetchType.LAZY) to other entities (say B & C). I can load an individual instance of A with a named query (using its ID) and add multiple successive instances of B to its respective Collection in A. This is verified in the database as well as in the app. However, when I load a different instance of A (with a different ID) and perform some work..., then return to re-load the original instance of A my findById named query returns NULL. This only happens after modifying the collection of B, in A.
Also, after adding each instance of B, a HibernateTemplate.merge takes place.
Details:My 'A' is a DevProject class, my 'B' is a DevProjectComment class.
Here is my OneToMany representation in A:
Code:
@OneToMany(mappedBy = "project", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
public Set<DevProjectComment> getComments() {
return this.comments;
}
Here is my ManyToOne representation in B:
Code:
@ManyToOne
@JoinColumn(name="project_id")
public DevProject getProject() {
return this.project;
}
Here is the NamedQuery, defined in A:
Code:
@NamedQuery(
name = "devProject.findByIdWithCollections",
query = "select d from DevProject d " +
"left join fetch d.documents " +
"left join fetch d.comments " +
"where d.id=:id"
)
Can anyone see what I cannot?