Hi,
I use hibernate 2.1.6.
I have defined three Entities: Product, Vehicle, SparePart.
class Vehicle extends Product
{}
class SparePart extends Product
{}
I should use table per concrete class using implicit polymorphism, which means that each Entity (Product, Vehicle, SparePart) has its own table.
Now I have the following mapping file:
<hibernate-mapping>
<class name="xx.yy.AssociatedEntity" table="AssociatedEntity">
<cache usage="read-write"/>
<composite-id>
…
<key-many-to-one name="product" column="product" class="xx.yy.Product"/>
…
</composite-id>
…
<property name="propertyY"/>
…
</class>
</hibernate-mapping>
I want to find some AssociatedEntity objects for a product:
…
Product product = get the product…
net.sf.hibernate.Criteria crit = hSession.createCriteria(AssociatedEntity.class);
crit = crit.add(Expression.eq("product", product));
crit.list();
…
When the product is a xx.yy.Vehicle or xx.yy.SparePart (not just xx.yy.Product) I get the exception:
No row with the given identifier exists: d0e0c3cb0634eaf8010634ec54d80005, of class: xx.yy.Product
That is right while this identifier is not present in the Product Table itself but in Vehicle or SparePart Table.
In the hibernate reference I found that in case of implicit polymorphism the association is mapped using <any> (instead of <many-to-one>).
But the problem is that the <any> element is not accepted inside a <composite-id> element, but my 'product' column should be part of the primary key, and my product can be either xx.yy.Product or xx.yy.Vehicle or xx.yy.SparePart
What could be the solution in this case?
Thanks,
Tamas
|