Suppose we have class A which has a list of class B objects (List<B>
listOfBs). In database design this means that table representing class B should have a foreign key referring to rows of table representing class A. Now, class B is a superclass of class C, D and E.
My hibernate mapping file of class A is the following and works fine for storing class A entries to the database and also cascading at the same time multiple entries of class B that are contained in the list of class A.
Class A Hibernate Mapping File:
<hibernate-mapping package="...">
<class name="A" table="table_of_A">
<id name="key" column="A_ID">
<generator class="native"/>
</id>
<property name="...." type="long"/>
<property name="...." type="string"/>
<list name="listOfBs" access="field" cascade="all">
<key column="A_ID" not-null="true" />
<list-index column="idx"/>
<one-to-many class="B"/>
</list>
</class>
</hibernate-mapping>
I am trying to figure out what I should include to the hibernate file shown above so I can store in the database the listOfBs which might containts objects of class C, D and E and therefore each of the object on the listOfBs should go to the appropriate table in the database. Note that I am using the table per concrete class with implicit polymorphism strategy for mapping inheritance on hibernate.
Any help would really appreciated. Thanks in advance.