[hibernate-dev] Eager fetch and duplicates of collection elements

Steve Ebersole steve at hibernate.org
Thu Feb 11 09:13:11 EST 2016


We can make that change in SQM,  but its not an option to change that
before.

But Gunnar your load use case would be a bug if true

On Thu, Feb 11, 2016, 7:55 AM Vlad Mihalcea <mihalcea.vlad at gmail.com> wrote:

> Hi,
>
> True. I also wondered why don't we use the DISTINCT as the default
> mechanism.
> While the underlying SQL would return a result-set according to the total
> number of joined relations, we are building the entity tree hierarchy and
> I don's see why a user would be interested in getting duplicate root entity
> objetc references.
>
> If I want to fetch the parent entity along with all its children, then I'd
> rather expect to see distinct parent objects than an object reference for
> each child entity.
>
> Vlad
>
> On Thu, Feb 11, 2016 at 3:48 PM, Gunnar Morling <gunnar at hibernate.org>
> wrote:
>
> > Hi,
> >
> > I understand that $subject is a known source of confusion for people
> > when working with HQL/criteria queries and not applying something like
> > DistinctRootEntityResultTransformer.
> >
> > I am seeing the same behaviour though when getting a root entity by id
> > and join-fetching two (nested) collections. That's my model:
> >
> >     @Entity
> >     public class Parent {
> >
> >         @Id @GeneratedValue
> >         private Long id;
> >
> >         @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
> >         @JoinColumn(name = "parent_id")
> >         private List<Child> children = new ArrayList<>();
> >     }
> >
> >     @Entity
> >     public class Child {
> >
> >         @Id @GeneratedValue
> >         private Long id;
> >
> >         @ElementCollection(fetch=FetchType.EAGER)
> >         @JoinTable(name = "Child_Properties")
> >         @MapKeyColumn(name = "key")
> >         @Column(name = "value")
> >         private Map<String, String> properties = new HashMap<>();
> >     }
> >
> > I am persisting a parent with one Child which has three "properties"
> > entries. Loading the Parent by id yields three elements in the
> > "children" list:
> >
> >     Parent loaded = session.get( Parent.class, 123 );
> >     assert 1 == loaded.getConfigurations().size(); // <!-- Fails, it
> > contains the same Child three times
> >
> > I don't think that's expected?
> >
> > I can file an issue, but first wanted to make sure I am not missing
> > anything obvious.
> >
> > Thanks,
> >
> > --Gunnar
> > _______________________________________________
> > hibernate-dev mailing list
> > hibernate-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/hibernate-dev
> >
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>


More information about the hibernate-dev mailing list