I'm having trouble choosing hibernate to return a properly populated object graph when select contains joins in many collections.
For instance:
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";
- There are many ChangeEntries in the change set.
- There is one RepositoryEntity object in ChangeEntry
- There is one repository in RepositoryEntity.
The above statement returns the correct data, but the object graph is incorrectly populated - that is, each set of changes contains each ChangeEntry, and not just its own children.
Here are the relevant fragments of these two classes:
public class Changeset { @NotNull @OneToMany(mappedBy="changeset", targetEntity=ChangeEntry.class, cascade={CascadeType.ALL }, fetch=FetchType.EAGER ) private Set<IChangeEntry> changeEntries;
A...
public class ChangeEntry { @NotNull @ManyToOne(targetEntity=Changeset.class) @ForeignKey(name="FkChangeEntryChangeset") private IScmChangeset changeset; @NotNull @ManyToOne(targetEntity=RepositoryEntity.class, cascade=CascadeType.ALL,fetch=FetchType.EAGER) @ForeignKey(name="FkChangeEntryRepoEntity") private IRepositoryEntity repositoryEntity;
Any help is appreciated
Hello
Marty
source share