Categories
hibernate loader native sql

Load only some columns with Hibernate native SQL queries

I have a table on the database and I want to load only some columns from the result set, because the main object mapped in Hibernate has a relation with itself and the object is very big. 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?