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.
Java 7 or Java 6, Sql Server 2008
Sample generated SQL by Hibernate:
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_
left outer join
this_.id in (
subquery_.id as y0_
Please attach a testcase that reproduces this – thanks
Was able to pin point the issue.
This is caused by the inclusion of the fieldname of the associated entity itself in the projection.
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
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!
Bulk rejecting issues lacking a test case or recent response.