Hi
I have a question regarding persisting entites:
Lets say i have two tables,
TABLE A, TABLE B and the corresponding mapping classes are CLASS A and CLASS B respectively. TABLE B has a Foreign Key which refers to the Primary Key of TABLE A.
And CLASS A has a reference (property) of the CLASS B. And CLASS B has a reference (property) of the CLASS A. So the mapping looks like the following:
Code:
<class name="CLASSA" table="TABLEA">
<id name="ID" column="ID">
<generator class="assigned" />
</id>
..................
...some other properties....
.................
<one-to-one name="classB" class="CLASSB" cascade="persist"/>
</class>
<class name="CLASSB" table="TABLEB">
<id name="ID" column="ID">
<generator class="foreign">
<param name="property">classA</param>
</generator>
</id>
<one-to-one name="classA" class="CLASSA" constrained="true"/>
..................
...some other properties....
.................
</class>
If during persistence, if a
save() method is called by passing only an instance of "CLASSA", does hibernate inserts into two tables "TABLEA" and "TABLEB" or we have to call
save() method explicitly for two entities i.e., CLASS A and CLASS B.
But based on hibernate documentation for parent/child entities, if
cascade="persist" option is used, then hibernate will take care of inserting into two tables. So, does CLASS B needs to extend CLASS A?
Can some body answer this?