I am using Hibernate 3 with a MySQL database (I tried with Hibernate 4 with no more success). I've implemented a table-per-concrete-class inheritance strategy (union-subclass).
It makes the job except for the polymorphic queries. Hibernate generates a UNION based query in which the "where" clause is in the high level query :
select primKey, param1, param2 from (
select primKey, param1, param2 from Concrete1
union
select primKey, param1, param2 from Concrete2
)
where primKey == <value>
order by param1
limit 100
This leads to very bad performance as the whole concrete tables content is loaded whereas, because pkey is an attribute of the abstract parent, the "where" clause could be defined in the subselects.
So the aim would be to get Hibernate generates this kind of query :
select primKey, param1, param2 from (
select primKey, param1, param2 from Concrete1 where primKey == <value>
union
select primKey, param1, param2 from Concrete2 where primKey == <value>
)
order by param1
limit 100
This way, the query is executed instantaneously.
Any idea of how I can configure Hibernate to change this behaviour ?
Thanks
Y.