Load only some columns with Hibernate native SQL queries

Posted by Alessandro Dionisi on Stack Overflow See other posts from Stack Overflow or by Alessandro Dionisi
Published on 2011-01-05T10:32:23Z Indexed on 2011/01/06 12:53 UTC
Read the original article Hit count: 192

Filed under:
|
|
|
|

I have a table on the database and I want to load only some columns from the result set. I defined a native sql query in the hbm file:

    <sql-query name="query">
  <return alias="r" class="RawData"/>    
     <![CDATA[
       SELECT DESCRIPTION as {r.description}
       FROM RAWD_RAWDATAS r       
       WHERE r.RAWDATA_ID=?
      ]]>
 </sql-query>

This query however fails with error: could not read column value from result set: RAWDATA1_14_0_; Invalid column name SQL Error: 17006, SQLState: null, because Hibernate tries to load all fields from the result set. I found also a bug in Hibernate JIRA (http://opensource.atlassian.com/projects/hibernate/browse/HHH-3035). Anyone knows how to accomplish this task with a workaround?

© Stack Overflow or respective owner

Related posts about sql

Related posts about hibernate