Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 1
    Hi, DISTINCT works, but I would like to understand why Hibernate can not process these children records as in case of 1:M relation, the result of SQL with 1:M relation has duplicates as well but Hibernate correctly merge all rows with primary key of FROM entity together and creates Entity object. Commented Aug 17, 2021 at 16:25
  • 1
    Unfortunately, this problem is on the Hibernate side. The official documentation says: "Queries that make use of eager fetching of collections usually return duplicates of the root objects, but with their collections initialized. You can filter these duplicates through a Set." link Commented Aug 17, 2021 at 21:48
  • Well the default ManyToMany Fetch is LAZY. Returning SET (or using distinct) works fine buts its still kind of a workaround. I would like to Hibernate to be able to JOIN FETCH many childrens without duplicates (as it does in case of 1:M) Commented Aug 20, 2021 at 9:15
  • This is wierd. Using a subselect will return the correct values but the subselect is not going to be as fast. Commented Feb 27, 2023 at 9:15