Hi All -
I'm stumped on how to map a collection of subclasses in such a way that each collection of subclasses is initialized with only "subclass" type of entities.
background:
Our db schema, however bad, is such that:
- we have Parent and Child entities
- child entities are one of 3 "types", (think type=discriminator; 3 subclasses)
- Parent has 3 collections - one for each "type" of child
- Parent-Child mapping is stored in a single mapping table with 2 columns (parent id and child id)
2 possible approaches:
1. use discriminator - this is a problem, since collections do not pay attention to discriminator value when loaded (according to
http://forum.hibernate.org/viewtopic.ph ... n+subclass). Result is that if Parent has 10 children of type x, 5 children of type y, 6 children of type z - the Parent collections end up with 21 objects each.
2. use where clause in collection mapping - this is a problem, since the discrimintor column is not available in the mapping table. I'm not sure if the sql generated in this case is correct, but it will not work in this case - the "where" attribute is assumed (by hibernate) to be applied to the table referenced in the collection mapping (i.e. my parent-child mapping table), instead of the child table.
example mapping:
<bag
name="offers"
table="eye_offer_category"
lazy="true"
inverse="false"
cascade="none"
order-by="offer_sys_id"
where="offer_type=0"
>
<jcs-cache
usage="read-write"
/>
<key
column="target_category_sys_id"
/>
<many-to-many
class="com.eyetide.model.Offer"
column="offer_sys_id"
outer-join="auto"
/>
</bag>
Offer mapping is something like:
<class
name="com.eyetide.model.Emu"
table="eye_offer"
dynamic-update="false"
dynamic-insert="false"
>
<property
name="offerType"
type="com.eyetide.constants.OfferType"
update="true"
insert="true"
column="offer_type"
/>
this generates sql like:
...from eye_offer_category alias1, eye_offer alias2 where alias1.offer_type=0...
which is bogus (should be "alias2.offer_type=0")
any thoughts?
thanks
tyson