I have a Single table per class hierarchy mapping (single table).
I have an abstract base with two subclasses.
Basically I want to execute a polymorphic query - meaning I want a query that returns a list of the base class.
Problem is that I have a different "where clauses" for every subclass and the where clauses are based on properties unique for the subclass (do not exist in the base class).
Seems like a union is required. So HQL is not really an option. I tried using something like
select {gv.*}, gv.Product_id from zad_videos gv where gv.widget_id = :wid " + union all select {pv.*}, pv.title, pv.user_id, pv.widget_id from zad_videos pv join zad_catalog_products cp on pv.product_id = cp.product_id where cp.catalog_id = :catid
and .addEntity("gv", superclass1) + .addEntity("pv", superclass2)
the problem is that each sql in the union generates the fields based on the entity it is mapped to with the addentity so the SQLs do not match as should be in the UNION.
The problem with HQL is that I will have something like
"select b from BaseClass b .....where... "
and then I need to access (in the where) b.property which is based on the actual type - a property that does not exist in the base class - Is there a way to handle this properly?
Thanks, Arie
|