Criteria projection produces duplicate SQL Alias between the root entity identifier and the next column to it

Description

With any query using criteria with projections, hibernate automatically includes another column for the identifier proiperty of the root entity in the select clause having a duplicate sql alias with the next column. Even though I have already included the identifier property, it includes it again, and it causes a duplicate sql alias which of course breaks the result mapping especially if the next column to the auto inserted identifier hasn't the same data type.

Environment

Java 7 or Java 6, Sql Server 2008

Activity

Show:
Vine Rustia
November 25, 2013, 7:15 AM

Sample generated SQL by Hibernate:

select
cargoitem1_.att_line_item as y0_,
this_.audit_logs_id as y1_,
cargoitem1_.cargo_id as y2_,
this_.created_by as y3_,
cargoitem1_.updated_by as y4_,
cargoitem1_.id as y5_,
cargoitem1_.created_date as y6_,
this_.asset_tag as y7_,
this_.updated_by as y8_,
this_.updated_by as y9_,
this_.id as y10_,
cargoitem1_.item_description as y11_,
this_.id as y12_,
cargoitem1_.att_asset_tags as y12_,
this_.is_good_condition as y13_,
this_.quantity as y14_,
cargoitem1_.quantity as y15_,
this_.created_date as y16_,
cargoitem1_.callout as y17_,
this_.audit_logs_id as y18_,
this_.updated_date as y19_,
cargoitem1_.line_id as y20_,
cargoitem1_.cargo_id as y21_,
this_.cargo_item_id as y22_,
cargoitem1_.callout_line as y23_,
this_.cargo_item_id as y24_,
cargoitem1_.created_by as y25_,
this_.created_by as y26_,
cargoitem1_.created_by as y27_,
cargoitem1_.updated_date as y28_,
cargoitem1_.updated_by as y29_,
this_.notes as y30_,
cargoitem1_.id as y31_,
cargoitem1_.mfg_item_number as y31_
from
cargo_item_audit_logs this_
left outer join
cargo_item cargoitem1_
on this_.cargo_item_id=cargoitem1_.id
where
this_.id in (
select
subquery_.id as y0_
from
cargo_item_audit_logs subquery_
where
(
subquery_.audit_logs_id=?
)
)
order by
y10_ desc

Brett Meyer
November 25, 2013, 2:48 PM

Please attach a testcase that reproduces this – thanks

Vine Rustia
November 28, 2013, 7:56 AM
Edited

Was able to pin point the issue.

This is caused by the inclusion of the fieldname of the associated entity itself in the projection.
For example,

UserAccount userAccount is an associated entity within Cargo entity.
Using Hibernate classmetadata, I have included all property fields, which also includes
userAccount field in the projection such as Projection.property("userAccount").
This caused hibernate to substitute this column with the root entity identifier field
with a duplicate sql alias relative to the next column in the projection list.

Though the primary root cause has been fixed in my end, but I think hibernate should
just throw an exception if the client code is including the associated entity field in the
projection.

Brett Meyer
December 19, 2013, 10:31 PM

Note: In an attempt to clean up the HHH JIRA, we will be rejecting any ticket that sits in the "Awaiting Test Case" state for 2-3 months with no response. So, if this issue is critical to you, please attach a reproducing test case ASAP. Thanks!

Brett Meyer
March 3, 2014, 3:40 PM

Bulk rejecting issues lacking a test case or recent response.

Assignee

Unassigned

Reporter

Vine Rustia

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