-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: individual updates for FK on Sets
PostPosted: Mon Jan 08, 2007 7:31 am 
Newbie

Joined: Mon Jan 08, 2007 7:06 am
Posts: 1
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.
    2. insert of 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.
    2. insert of 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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.