Hibernate version: 3
Maybe I want too much from hibernate, but is it possible to change a type of the subclass?
I vave 3 tables: CAT, DOMESTIC_CAT, WILD_CAT. DOMESTIC_CAT, WILD_CAT is in one-to-one relation with CAT. These tables are mapped to a 3 classes - Cat (abstract) and subclasses - DomesticCat and WildCat.
Code:
<class name="Cat" table="CAT">
... some properties ...
<joined-subclass name="DomesticCat" table="DOMESTIC_CAT">
<key column="CAT_ID" />
... some properties ...
</joined-subclass>
<joined-subclass name="WildCat" table="WILD_CAT">
<key column="CAT_ID" />
... some properties ...
</joined-subclass>
</class>
Code:
Cat cat = session.get(WildCat.class, id);
// now somehow change the type to DomesticCat
DomesticCat cat2 = changeTypeToDomesticCat(cat);
cat2.setOwner("Fred");
session.update(cat2); // ???
Is this possible in Hibernate? If yes, then how? Using JDBC I would delete one row from WILD_CAT and add one row to DOMESTIC_CAT. Using hibernate I can now only delete the "old" cat completly (delete two records - from table CAT and WILD_CAT) and then add new cat (insert two records - to table CAT and DOMESTIC_CAT). Moreover if cat uses some other child relations, they must be deleted / inserted too (without any change to their properties).
Thanks in advance
Martin