Skip to content

JPA #fetchOne returns invalid results #1596

@fanste

Description

@fanste
  • I am willing to put in the work and submit a PR to resolve this issue.

As of Hibernate 6, the implementation regarding #getSingleResult() changed which effectively disabled the automatic deduplication logic. Since Hibernate 7.3 the feature is fully removed and the query itself has to ensure, that only a single result is returned. This is also possible by adding a ResultListTransformer (see https://docs.hibernate.org/orm/7.3/migration-guide/#_result_deduplication and https://github.com/hibernate/hibernate-orm/pull/11470/changes).

This means, that in case of Hibernate, we should add the mentioned transformer or provide a own implementation, in case the provided one is not functional equivalent to pre-hibernate-6 times.

query.setResultListTransformer(ResultListTransformer.uniqueResultTransformer())

An other solution would be to generally provide a custom solution for this and run a custom deduplication after the query returned it's result. This would apply to all possible JPA vendors.

What is the preferred solution? Hibernate specific or QueryDSL sepcific?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions