I am using Hibernate support for the inheritance strategy TABLE_PER_CLASS. Functionality is wise; it works well. Whenever a polymorphic query is issued, Hibernate generates SQL containing "union all" for my two specific classes A and B. The generated SQL has the following format:
select C1, C2, C3 from (
select C1, C2, C3 from ClassA
union all
select C1, C2, C3 from ClassB
)
where
C1 == <value>
order by C2
limit 100
The problem with this approach is suffering from very poor database performance. Given that column C1 is a common property of ClassA and ClassB (derived from an abstract parent), Hibernate can insert a where clause into both selections and significantly improve performance. For instance,
select C1, C2, C3 from (
select C1, C2, C3 from ClassA where C1 == <value>
union all
select C1, C2, C3 from ClassB where C1 == <value>
)
order by C2
limit 100
.
API Hibernate DAO.
, onPrepareStatment() , .
, , , .
, ?