[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4174) native SQL queries in hibernate don't work when using aliases to differentiate columns that have the same name

Aviad Lichtenstadt (JIRA) noreply at atlassian.com
Thu Feb 17 19:28:05 EST 2011


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

Aviad Lichtenstadt commented on HHH-4174:
-----------------------------------------

I have just encountered this issue with mysql
But also with the latest version of HQLDB.
Mysql has a driver flag to fix this issue:
useOldAliasMetadataBehavior=true

Butfor HSQLDB there is no solution and since they are implementing the correct jdbc spec i suggest Hibernate will do something about it

> native SQL queries in hibernate don't work when using aliases to differentiate columns that have the same name
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-4174
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4174
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: entity-manager
>         Environment: jboss 4.2.2, mysql 5
>            Reporter: Alex McCarrier
>
> Basically same as HHH-2094, if you do something like this:
> select 
>   oldForm.data as oldData
>   newForm.data as newData
> from 
>   form oldForm,
> join form newForm on oldForm.replaced_by_id = newForm.id
> then use entityManager.createNativeQuery(sql).getResultList()
> it will end up with an error that says column named oldData does not exist.  If you take out the aliases, then it will just return the first value for "data" for every column.  If you run this through straight JDBC with the alias,  it works as expected.   

-- 
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