'm having trouble getting a hibernate select to return a correctly populated object graph, when the select contains joins across many collections.
Eg:
Code:
String sql = "select distinct changeset " +
"from Changeset changeset " +
"join fetch changeset.changeEntries as changeEntry " +
"join fetch changeEntry.repositoryEntity as repositoryEntity " +
"join fetch repositoryEntity.repository as repository " +
"where repository.connectionName = :connectionName";
A Changeset has many ChangeEntries
A ChangeEntry has one RepositoryEntity
A RepositoryEntity has one Repository
The above statement returns the correct data, but the object graph is not correctly populated -- ie., each Changeset contains every ChangeEntry, not just it's own children.
Here's the relevant snippets of those two classes:
Code:
public class Changeset {
@NotNull
@OneToMany(mappedBy="changeset", targetEntity=ChangeEntry.class, cascade={CascadeType.ALL }, fetch=FetchType.EAGER )
private Set<IChangeEntry> changeEntries;
And...
Code:
public class ChangeEntry extends BaseEntity implements IChangeEntry {
@NotNull
@ManyToOne(targetEntity=RepositoryEntity.class, cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@ForeignKey(name="FkChangeEntryRepoEntity")
private IRepositoryEntity repositoryEntity;
Any assistance is greatly appreciated
Regards
Marty