[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6783) Using FetchType.EAGER with @ElementCollection results in multiple entity copies returned via Criteria query

Greg Burcher (JIRA) noreply at atlassian.com
Thu Nov 3 09:58:22 EDT 2011


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

Greg Burcher commented on HHH-6783:
-----------------------------------

The work-around seems simple enough, but the problem is that we would need to add this call to setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) to every use of Criteria.list(). Otherwise, at any point in time, someone could change the mapping of an @ElementCollection to EAGER and suddenly the Criteria.list() would be "broken", returning multiple references to the same object.

This is a cumbersome convention to enforce in our entire codebase. We could handle by wrapping the hibernate Session or Criteria in our own class and adding the call to setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) always in our wrapper, but this is a significant design decision to correct what feels like an error in hibernate, even if you guys say it is not a bug.

I'm guessing since you have already published a FAQ on this issue, you are not likely to change this behavior?

> Using FetchType.EAGER with @ElementCollection results in multiple entity copies returned via Criteria query
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-6783
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6783
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: annotations
>    Affects Versions: 3.6.0
>         Environment: MySQL
>            Reporter: Greg Burcher
>
> If we specify FetchType.EAGER on an @ElementCollection:
>     @ElementCollection(fetch = FetchType.EAGER)
>     @Column(name = "emailAddress")
>     private Set<String> emailAddresses;
> then request all persisted objects of this class via Criteria:
>     session.createCriteria(ReportSchedule.class).list();
> The returned list contains multiple references to each ReportSchedule, one per email address.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list