-->
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: Map subclass to parent class table with <join>
PostPosted: Fri Dec 22, 2006 7:52 am 
Newbie

Joined: Tue Jul 26, 2005 6:16 am
Posts: 2
Location: Russia, Moscow
Hello!
I have 3-level class hierarchy:

Code:
class RootClass {
   Integer id;
}

class Product extends RootClass {
    Double price;
}

class SubProduct extends Product {
    String color;
}


RootClass is mapped to "root" table:
Code:
<class name="RootClass" table="root">
    <id unsaved-value="null" type="int" name="id">
        ....
    </id>
    <discriminator column="classType"/>
    ...
</class>


Product class is mapped to products table via join:
Code:
<subclass name="Product" extends="RootClass">
     <join table="products">
         <key column="id"/>
         <property name="price" not-null="true"/>
     </join>
</subclass>


I want to map SubProduct class to same table as Product class. How can I do such mapping?
Variant 1:
Code:
<subclass name="SubProduct" extends="Product">
     <join table="products">
         <key column="id"/>
         <property name="color"/>
     </join>
</subclass>

This mapping don't work - when I call save(), Hibernate tries to insert row to "products" table twice (first row for Product mapping and second row for SubProduct mapping.)

Variant 2:
Code:
<subclass name="SubProduct " extends="Product">
         <property name="color"/>
</subclass>

In this case, Hibernate creates "color" column in a root class table ("root"). "products" table is not used at all.

Any suggestions?


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.