[hibernate-issues] [Hibernate-JIRA] Closed: (HHH-2094) Hibernate is ignoring native sql aliases and generating "column not found" error

Max Rydahl Andersen (JIRA) noreply at atlassian.com
Thu Sep 21 21:22:25 EDT 2006


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2094?page=all ]
     
Max Rydahl Andersen closed HHH-2094:
------------------------------------

    Resolution: Rejected

we don't parse the sql, we use the mapping info as default to know what column goes to what property.

if you decide to rename those you should mark it as such with <return-property> or use the {} syntax.

we don't use positional columns since they don't make sense - how can we know which order you placed them in.

> Hibernate is ignoring native sql aliases and generating "column not found" error
> --------------------------------------------------------------------------------
>
>          Key: HHH-2094
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2094
>      Project: Hibernate3
>         Type: Bug

>   Components: query-sql
>     Versions: 3.2.0.cr4
>  Environment: 3.2.0.cr4, Adaptive Server Enterprise/12.5.3
>     Reporter: Leonardo Penczek
>     Priority: Critical

>
>
> As simples as that:
> 1: Query q = em.createNativeQuery("select cd_person as codePerson, cd_person as identif from PERSON");
> 2: List<Object[]> resultList = (List<Object[]>) q.getResultList();
> Hibernate is ignoring my aliases when retrieving information from the ResultSet because it is trying to retrieve by column name, generating the following error:
> javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
>         at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:641)
>         at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:73)
>         at <my line 2 in the code above>
> ...
> Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
>         at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
>         at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
>         at org.hibernate.loader.Loader.doList(Loader.java:2147)
>         at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
>         at org.hibernate.loader.Loader.list(Loader.java:2023)
>         at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
>         at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
>         at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
>         at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
>         at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
>         ... 
> Caused by: java.sql.SQLException: S0022: Invalid column name 'cd_person'.
>         at com.sybase.jdbc3.jdbc.ErrorMessage.raiseError(Unknown Source)
>         at com.sybase.jdbc3.tds.TdsResultSet.findColumnByLabel(Unknown Source)
>         at com.sybase.jdbc3.jdbc.SybResultSet.findColumn(Unknown Source)
>         at com.sybase.jdbc3.jdbc.SybResultSet.getInt(Unknown Source)
>         at org.jboss.resource.adapter.jdbc.WrappedResultSet.getInt(WrappedResultSet.java:690)
>         at org.hibernate.type.IntegerType.get(IntegerType.java:28)
>         at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
>         at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:139)
>         at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.extract(CustomLoader.java:474)
>         at org.hibernate.loader.custom.CustomLoader$ResultRowProcessor.buildResultRow(CustomLoader.java:420)
>         at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:317)
>         at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:594)
>         at org.hibernate.loader.Loader.doQuery(Loader.java:689)
>         at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
>         at org.hibernate.loader.Loader.doList(Loader.java:2144)
> Awesome! The SQL query runs, but the Hibernate try to get the column by the original name, not by the alias, causing the error!
> It is not possible to correctly get the value of 2 different columns that have the same name!!!!
> Hint: why Hibernate use ResultSet.get* by column name instead of positional ResultSet.get* (1, 2, 3,...)? It will solve this problem.

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