Hello all.
I have a problem with a collection with implicit polimorphizm. I have classes: Container (table CONTAINER), Parent (PARENT) and Child(CHILD). Child extends Parent. Container has a set of Parent objects, mapped like this:
<set name="parents" table="PARENT" cascade="save-update, delete, delete-orphan" inverse="true">
<key column="CONTAINER_ID" />
<one-to-many class="Base" />
</set>
The set in Container is HashSet<Parent>.
Both Parent and Child are mapped separately to their corresponding tables, and have the Container property:
<many-to-one name="container" class="Container" column="CONTAINER_ID" foreign-key="PARENT_TO_CONTAINER_ID" />
Now, in the code I create both Parent and child objects and add them to the collection. When I save the container, all the objects are inserted into the PARENT table, the CHILD is empty.
How can I change the mappings so that Child objects would be saved in the CHILD table? Is it possible with implicit polymorphizm, or do I have to use some other strategy to store hierarchies?
|