I am by no means an expert in SQL, but if you need to manipulate the
data during retrieval, and you want to try and solve this problem via
mapping files, then your best bet would be to use the "where" attribute
of the <class> element in the mapping file. This should allow you to
set conditions during the retrieval of the records in this table.
so...
> <class name="ReferenceTable"
> table="REFERENCE_TABLE" where="[SQL code]">
[quoted text clipped - 9 lines]
>
> </class>
Dunno if that helps...
> Hello,
>
[quoted text clipped - 78 lines]
>
> Any advice is greatly appreciated.
ducnbyu - 08 Sep 2006 01:42 GMT
> I am by no means an expert in SQL, but if you need to manipulate the
> data during retrieval, and you want to try and solve this problem via
[quoted text clipped - 19 lines]
>
> Dunno if that helps...
It helps in a big way! The where= itself doesn't help but, as I'm
still learning Hibernate, you prompted me to take a close look at the
Class definition documentation and found the <subselect>.
So I did this and it works:
<class name="ReferenceTable"
table="REFERENCE_TABLE">
<subselect>
select indexed_column,
coalesce(unindexed_column, ' ') as unindexed_column,
field, ..., more_fields
from reference_table
</subselect>
<composite-id>
<key-property name="indexedColumn"
column="INDEXED_COLUMN"/>
<key-property name="unindexedColumn"
column="UNINDEXED_COLUMN"/>
</composite-id>
<property ... />
</class>
The generated SQL puts the subselect into an in-line view:
SELECT reference0_.indexed_column AS ind1_9_0_,
reference0_.unindexed_column AS uni2_9_0_,
reference0_.field AS fie3_9_0_, ...,
reference0_.more_fields AS mor4_9_0_
FROM
(SELECT indexed_column,
COALESCE (unindexed_column, ' ') unindexed_column,
field, ..., more_fields
FROM refrence_table) reference0_
WHERE reference0_.indexed_column = ?
AND reference0_.unindexed_column = ?
Since unindexed_column is not indexed, peformance is not lost using it
in an expression. The Explain Plan is correct too. Thanks so much for
the lead you gave!