Hello,
I have a general question and (based on the answer to that question) a specific question about an issue I'm trying to work out.
First question:
When you save a brand new parent object which has a set of child objects (one-to-many collection) do you explicitly have to set the foreign key id of the child to match the generated id of the parent?
Second Question:
If the answer is no, then what am I missing here? When I saveOrUpdate on my parent object, it saves fine, however the generated id (which is the primary key for the parent) does not get set on the child objects (which is a foreign key to the parent's primary key)
My parent object is called Matches and my child object is called Activities
Mapping documents:
Code:
<hibernate-mapping>
<class name="Match" table="Matches">
...
<set name="matchedActivities" cascade="all-delete-orphan">
<key column="MatchId"/>
<one-to-many class="Activity"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="Activity" table="MatchedActivities">
<composite-id name="primaryKey" class="ActivityPrimaryKey">
<key-property name="refId" type="java.lang.String" column="RefId"/>
<key-property name="refSrc" type="java.lang.String" column="RefSrc"/>
</composite-id>
<property
name="matchId"
type="java.lang.Integer"
update="true"
insert="true"
column="MatchId"
/>
</class>
</hibernate-mapping>
When I call saveOrUpdate, it complains that it cannot save a null value into MatchActivities.MatchId.
Thanks in advance for any help.