SQLQuery with join returns the joined entity instead of the root one

Description

Considering the following parent entity:

and its child-side relationship:

Hibernate returns a List<Call> instead of a List<Person>.

Environment

None

Activity

Show:
Gail Badner
February 24, 2016, 2:04 AM

Criteria.DISTINCT_ROOT_ENTITY is intended to be used with an org.hibernate.Criteria. It should not be used with native queries.

Vlad Mihalcea
February 24, 2016, 7:14 AM
Edited

The bug still replicates when using the DistinctRootEntityResultTransformer:

Instead of a List of Phone we get a List of Call objects.

This issue needs to be reopened.

Gail Badner
February 25, 2016, 9:48 PM

DistinctRootEntityResultTransformer assumes that the root entity is last. IIRC, an HQL query returns the root entity last, so DistinctRootEntityResultTransformer should work properly for an HQL query.

The transformer would probably work for a native query using a SELECT clause like: SELECT c., ph. ...". If so, I'm OK with re-opening this as a documentation issue. WDYT?

Vlad Mihalcea
February 26, 2016, 5:36 AM

It works for the HQL queries I created for the User Guide.
For SQL queries, even if I rewrite it like this:

the result will be a List<Call> instead of a List<Phone>.

Rejected

Assignee

Gail Badner

Reporter

Vlad Mihalcea

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure