-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: implicit polimorphism in a <composite-id>
PostPosted: Thu Sep 08, 2005 11:38 am 
Newbie

Joined: Thu Sep 01, 2005 9:55 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.