[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2575) Query results are mapped to object array incorrectly when there is column ambiguity and aliases are not used

Mike Hoeffner (JIRA) noreply at atlassian.com
Tue Mar 16 19:44:48 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=35844#action_35844 ] 

Mike Hoeffner commented on HHH-2575:
------------------------------------

The original examples would be clearer if I didn't show them as using the same "foo" table.  These are not realistic queries but adding joins and where clauses would only  distract from the part that matters.

Incorrect results.  Those from b will be "overshadowed" by those from a:

{code}
select a.name, a.seq, b.name, b.seq from apple a, banana b;
{code}

Proper results:

{code}
select a.name as a_name, a.seq as a_seq, b.name as b_name, b.seq as b_seq from apple a, banana b;
{code}


> Query results are mapped to object array incorrectly when there is column ambiguity and aliases are not used
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-2575
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2575
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: query-sql
>    Affects Versions: 3.2.2
>         Environment: Hibernate 3.2.2 + MySQL 5.0.22 + MySQL Connector/J 5.0.5.  Reproduced with HSQLDB 1.8.0.7.
>            Reporter: Mike Hoeffner
>            Priority: Minor
>         Attachments: ResultsNotEffectedByAliasesTest.java
>
>
> I had a SQL (not HQL) query that basically looked like this:
>      select a.name, a.seq, b.name, b.seq from foo a, foo b;
> and I noticed that the results obtained through list() -> (Object[]) get(i) -> row[0], row[1], row[2], row[3]
> did not correspond to what I saw when manually running the query without Hibernate involved.  row[2] always had the same values as row[0] and row[3] always had the same values as row[1].
> When I tried adding aliases so that it became:
>      select a.name as a_name, a.seq as a_seq, b.name as b_name, b.seq as b_seq from foo a, foo b;
> then the results matched what I expected.  So having aliases in the SQL modified the results that were returned even though I was looking up the value from each column by its index / position instead of by its name / alias.
> Attached is a test case that will reproduce this.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list