I'm using multiple hibernate named queries that maps to the same hibernate class.
The problem is because the different named queries return different attributes, and not all the attributes I'm getting an "invalid column" error. The way to resolve it is to make sure the queries map all the attributes defined by the hibernate class. (Hibernate native query : Invalid Column Name Error SQL-17006)
Here's an sample of what I have:
<hibernate-mapping>
<class name="com.company.ObjectA" mutable="false" >
<id name="id" type="string"/>
<property name="prop1" type="string"/>
<property name="prop2" type="string"/>
</class>
<sql-query name="get1">
<return alias="a" class="com.company.ObjectA"/>
<![CDATA[
select
id as {a.id},
prop1 as {a.prop1}
from TABLE_A
]]>
</sql-query>
<sql-query name="get2">
<return alias="a" class="com.company.ObjectA"/>
<![CDATA[
select
id as {a.id},
prop2 as {a.prop2}
from TABLE_A
]]>
</sql-query>
</hibernate-mapping>
I have defined a temporary fix where the queries return empty values to make sure all hibernate class attributes are mapped:
<sql-query name="get2">
<return alias="a" class="com.company.ObjectA"/>
<![CDATA[
select
id as {a.id},
'' as {a.prop1},
prop2 as {a.prop2}
from TABLE_A
]]>
</sql-query>
But that is not ideal, because for my real case, I have quite a few of these unmapped attributes, and more named queries that use a different combination of attributes in the hibernate class.
Is there another way to resolve it? Also I need it to return data to the same object 'ObjectA', because of it's integration with the rest of the code.