[hibernate-issues] [Hibernate-JIRA] Issue Comment Edited: (HHH-5526) Dirty Entity instances in session after HQL queries with where conditions on OneToMany relation

Felix von Delius (JIRA) noreply at atlassian.com
Thu Sep 16 04:09:22 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5526?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=38414#action_38414 ] 

Felix von Delius edited comment on HHH-5526 at 9/16/10 3:09 AM:
----------------------------------------------------------------

> 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);
    crit.createAlias("persons", "p");
    crit.add(Restrictions.eq("p.id", teamMember.getId()));
    List<Team> teamList = crit.list();


      was (Author: fvdiba):
    > 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);
    crit.createAlias("persons", "p");
    crit.add(Restrictions.eq("p.id", teamMember.getId()));
    List<Person> teamList = crit.list();

  
> Dirty Entity instances in session after HQL queries with where conditions on OneToMany relation
> -----------------------------------------------------------------------------------------------
>
>                 Key: HHH-5526
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5526
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core, query-hql
>    Affects Versions: 3.3.2
>         Environment: Hibernate 3.3.2.GA, Java 1.6
>            Reporter: Felix von Delius
>            Assignee: Gail Badner
>
> 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.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list