Having a OneToMany relation on Team.persons, after you execute a HQL query in the form
"select distinct t from Team t join fetch t.persons p where p.id = ?"
the selected Team instance only contains the one person with the id searched for (i.e. missing other persons in this team).
Probably this could be worked around by changing the query, the main problem ist that this broken Team instance is attached in the session and querying for the team by it's id returns this broken team:
Team newTeamFetchedById = session.get(Team.class, TEAM_ID); // team id from the query above
Evicting the fetched team and repeating the query again fetches a team with the correct number of persons.
Hibernate 3.3.2.GA, Java 1.6
This is expected behavior.
> This is expected behavior.
Huh? When executing a query that starts with "select from Team t join fetch t.persons", I would expect to get the team with all it's members, independent of the where clause. And even if this is a idiosyncrasy of this specific query, executing another query in the same session where the team is selected by id, I would expect to get the complete team.
Btw: leaving out the "fetch" in the above query seems to return the team with all members.
If this is really the correct, expected behaviour, where is this "expected" behaviour documented?
Executing the same query as a criteria query does have the (IMHO) expected behaviour (returning the team with all it's members):
Criteria crit = session.createCriteria(Team.class);
List<Team> teamList = crit.list();
Bulk closing stale resolved issues