[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4956) Native Query returns wrong results

dubrov (JIRA) noreply at atlassian.com
Wed Jun 16 11:51:22 EDT 2010


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

dubrov commented on HHH-4956:
-----------------------------

Same (very similar) issue is reproducible with hibernate 3.5.0-Final.
Workarounds suggested here don't work.

Cause:

  hibernate tries to map ResultSet columns by their names.

Symptoms:

  1) result for columns "t1.fieldAA" and "t2.fieldAA" is taken from the same column "fieldAA"
  2) queries like "select t1.fieldAA alias from ..." fail to execute (hibernate can't find the column "fieldAA" in ResultSet)

Workaround?:

  despite "select t1.fieldAA ALIAS1, t2.fieldAA ALIAS2 from ..." being non-working, the following query works:
  "SELECT * from(select t1.fieldAA ALIAS1, t2.fieldAA ALIAS2 from ...) t"
  since all columns of this query have distinct names in ResultSet, e.g. "ALIAS1" and "ALIAS2"

P.S. Greetings from Estonia


> Native Query returns wrong results
> ----------------------------------
>
>                 Key: HHH-4956
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4956
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: query-sql
>    Affects Versions: 3.3.2
>         Environment: hibernate 3.3.2.GA , linux, oracle 10g, weblogic 10
>            Reporter: Akashdeep Saddi
>
> Issue: In-case running native queries vai hibernate we have two technical ID's in the select clause from join of two or more tables the value of all the id's is set to one value. 
>  
> Example
> A.id = 1
> B.id =2 
> select A.Id as A_ID, B.Id as B_ID from A, B where A.B_id = B.id will return 1,1 in the result instead of 1,2
>  
> Resolution: Use Alias in-case more than one technical keys are part of select clause. Above query works fine when changed as below
>  
> select A.Id , B.Id from A, B where A.B_id = B.id will return 1,2

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