[hibernate-issues] [Hibernate-JIRA] Created: (HHH-4544) createNativeQuery seems to return column values by name and not by column index

Karl Wettin (JIRA) noreply at atlassian.com
Tue Nov 3 22:48:57 EST 2009


createNativeQuery seems to return column values by name and not by column index
-------------------------------------------------------------------------------

                 Key: HHH-4544
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4544
             Project: Hibernate Core
          Issue Type: Bug
          Components: entity-manager
    Affects Versions: 3.2.4.sp1
            Reporter: Karl Wettin


Sorry, couldn't connect to the Hibernate forum, so I report it in here instead even though I'm not sure certain if it already has been solved.

Executing an SQL query using executeNativeQuery via a JPA entity manager will not return the same values in the columns as if I executed the query in my PostgreSQL prompt. The thing seems to be when I request the same field or table multiple times but using the same name.

{code:sql}
SELECT 
  price.currency, 
  price."value", 
  monthlyfee.currency, 
  monthlyfee."value", 
  bid.created, 
  auction.id, 
  auction.closed, 
  auction.firstseen, 
  auction.opened, 
  auction.lastseen, 
  brf.id, 
  brf."name", 
  brf.anno, 
  address.geocoded, 
  address.latitude, 
  address.longitude, 
  address.streetaddress, 
  address.decomposed, 
  address.housenumbersuffix, 
  address.streetname, 
  address.housenumber, 
  apartment.squaremetersexterior, 
  apartment.squaremetersinterior, 
  apartment.rooms, 
  apartment.floor,
  genericprimaryadvertisement.sourceurl,
  unharvestedprimaryadvertisement.sourceurl,
  brf.organizationnumber 
FROM 
  apartment   
LEFT JOIN auction ON auction.ownable_id = apartment.id 
LEFT JOIN address ON apartment.address_id = address.id
LEFT JOIN bid ON auction.mostrecentbid_id = bid.id
LEFT JOIN currency as price ON bid.price_id = price.id
LEFT JOIN currency as monthlyfee ON apartment.monthlyfee_id = monthlyfee.id
LEFT JOIN estate_apartment ON apartment.id = estate_apartment.apartments_id 
LEFT JOIN estate ON estate.id = estate_apartment.estate_id
LEFT JOIN estateownership ON estate.owner_id = estateownership.id
LEFT JOIN brf ON estateownership.owner_id = brf.id
LEFT JOIN unharvestedprimaryadvertisement ON auction.primaryadvertisement_id = unharvestedprimaryadvertisement.id
LEFT JOIN genericprimaryadvertisement ON auction.primaryadvertisement_id = genericprimaryadvertisement.id
ORDER BY auction.id
{code}

In this case the value for column 0 and 1 is always equal to the value of column 2 and 3 (currency and value) when using createNativeQuery but works just fine when executing the SQL manually in psql. The same thing goes for column 25 and 26, the sourceurl columns.

As the problem disapears when I specify unique names using AS in the FROM clauses my guess is that hib iterates the column names and not the column index, i.e. treating the columns in "FROM foo.a, bar.b" as the value from foo.a in both cases.

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