Hello,
I am relatively new to hibernate and have a question around optimising performance around the cascade save of new entity collections.
I have a simple one-to-many parent child relationship of objects. On save both the parent and all of its children are made persistent in one go. I have a custom id generator for both parent and child that basically just calls a Sybase stored proc (Legacy requirement) in order to retrieve the Id.
On calling session.save() on the parent object I would have expected this to result in the following sql statements:
1. custom id generator called for parent.
.... and then for each child .... 3. custom id generator called for child
4. insert of child with parent foreign key value populated
Instead, The following happens (in roughly this order) which (given a large number of children) is not very performant: 1. custom id generator called for parent.
.... and then for each child .... 3. custom id generator called for child.
4. insert of child with NO parent foreign key value populated.
5. update of child with parent foreign key value.
Is there any reason why the above occurs rather than my expected results (inappropriate mapping etc.) and if not is there anyway to force the initial insert of the child object to include the parent key?
I am using Hibernate version 3.2 against Sybase 12.5, the beans are simple POJOs using Sets for the collections and the simplified mapping document is as follows:
Code:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="DataLoadEvent" table="DataLoadEvent">
<id name="dataLoadEventId" column="dataLoadEventId">
<generator class="com.custom.SybaseStoredProcIDGenerator">
<param name="grabsize">20</param>
</generator>
</id>
<property name="dataLoadId" column="dataLoadId"/>
<property name="entityName" column="entityName"/>
<property name="entityId" column="entityId"/>
<property name="dateLoaded" column="dateLoaded"/>
<set name="dataLoadValues" cascade="all-delete-orphan">
<key column="dataLoadEventId"/>
<one-to-many class="DataLoadValue" />
</set>
</class>
<class name="DataLoadValue" table="DataLoadValue">
<id name="dataLoadValueId" column="dataLoadValueId">
<generator class="com.custom.SybaseStoredProcIDGenerator">
<param name="grabsize">30</param>
</generator>
</id>
<property name="dataLoadEventId" column="dataLoadEventId"/>
<property name="attributeName" column="attributeName"/>
<property name="attributeValue" column="attributeValue"/>
<property name="attributeType" column="attributeType"/>
</class>
</hibernate-mapping>