Query Parameters Not Bound Correctly

Description

When an entity has a compound key made up of, in part, another entity's compound key, it seems that Hibernate does not bind parameters to the correct columns in SQL translated from HQL. It seems that the routine used to build the SQL statement via Antlr can list primary key columns in a different order than the routine that builds parameter values via reflection. Bascially, you end up with a condition like:

PK_COL_1 = ? and
PK_COL_2 = ?

and the bound values are for kCol2 and kCol1 respectively. Depending on how an HQL query is written, you can actually get the query translator to build a join this way:

TABLE1.PK_COL_1 = TABLE2.PK_COL_2 and
TABLE1.PK_COL_2 = TABLE2.PK_COL_1

Depending on the data type, this can either cause an error or an empty result set. I did a good bit of debugging, but did not find an easy solution that didn't break something else worse. I did find that explicitly setting @JoinColumn.referencedColumnName in the child ID class did force things to work correctly against Oracle but MySQL is syntactically different enough that it does not work there. I will attach an example shortly.

Environment

Hibernate 3.6.0, Windows, Oracle 10g and MySQL 5.1

Activity

Show:
Brett Meyer
April 14, 2014, 12:42 PM

Thanks for the test case!

Steve Ebersole
October 27, 2015, 7:17 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/

Steve Ebersole
October 28, 2015, 3:24 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Christian Beikov
October 29, 2015, 1:45 PM

I just tried out the first testcase but I couldn't reproduce it. I guess this is obsolete.

Steve Ebersole
October 29, 2015, 2:11 PM

Thanks for verifying Christian

Assignee

Unassigned

Reporter

Erich Heard

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure