Hi,
I have a problem with cascaded insert in the following example.
//------------------ Mapping - parent ---------------------------
<class
name="ParentImpl"
table="Parent"
dynamic-update="true"
dynamic-insert="true"
>
<id
name="id"
column="Parent_Id"
type="string"
>
<generator class="assigned">
</generator>
</id>
<bag
name="children"
table="Children"
lazy="false"
inverse="true"
cascade="all"
>
<key
column="Parent_Id"
/>
<one-to-many
class="ChildImpl"
/>
</bag>
//----------------------- Mapping - child --------------------
<class
name="ChildImpl"
table="Child"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="string"
>
<generator class="assigned">
</generator>
</id>
<many-to-one
name="parent"
class="ParentImpl"
cascade="all"
outer-join="auto"
update="true"
insert="true"
column="Parent_Id"
not-null="true"
/>
//--------------------------------
In the Hibernate code, I have something like the following:
....
defaultParent = createParent("Kitzrow's");
Child diff = createChild("Diff");
...
Session session = persistLayerInstance.createSession();
persistLayerInstance.saveSession(session, defaultParent);
diff.setParent(defaultParent);
defaultParent.add(diff);
session.flush();
session.connection.commit();
...........
//---------------------------------------------
Now, Hibernate creates an "Insert" for the parent, but for the child it tries to do an "Update". Since the child row does not exist, it throws an error.
Now, I am trying to understand why is Hibernate doing an "update" when it is supposed to do an "insert". Any insights much appreciated...
Thanks,
Madhan.
|