[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1) Optimize Hibernate for the bulk insertion of related entities

Michael Kopp (JIRA) noreply at atlassian.com
Thu Nov 30 05:32:05 EST 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1?page=comments#action_25502 ] 

Michael Kopp commented on HHH-1:
--------------------------------

1) well in case of a merge sort you are right. I didn't think about that. But would traversing really be faster than a bubble sort in this case? i'm not sure about that.

But you are wrong that we need to consider hibernate entities. we need to consider EntityInsertActions. the state contains only what is to be inserted.
so 3) is a mute point because of that. if it is inverse there would be two insert actions where one state would refer the other, if it was not inverse there would still be two insert actions, but none would refer the other. the referral would be added  by an UpdateAction.


The following traversal would be possible.

- first build up a java.util.IdentityHashMap: EntityAction.instance --> EntityInsertAction
  and make that Map available to the to the InsertAction
  this can be done before calling the sort itself.

in the compare:
         final EntityInsertAction entityInsertAction = ((EntityInsertAction) other);
            final Object instance = entityInsertAction.getInstance();
            if (instance != getInstance())
            {
                // if any of our properties is actually to be inserted, it has to be before us
                int relation=0;
                for (int i = 0; i < state.length; i++)
                {
                    final Object rel = state[i];
                    if (rel == instance)
                    {
                        relation +=1; // the 'other' InsertAction inserts something that we need. it has to be before us in the queue
                    }else
                    {
                        EntityInsertAction related = insertActionMap.get(rel);
                        if (related != null) // we found a relation to another object. that must be definitely before us. lets see if other is a parent of related and thus a parent of us
                        {
                                relation += related.compareTo(entityInsertAction);
                        }
                    }
                }

and the same for the other way around. I haven't completely thought it through but I think this would work out.
- One thing to take care of is an endless loop here due to bidirectional 1-1 relations
- One other thing I hadn't considered are inverse unidirectional relations where only the parent has a relation to the child (collection). This would not be correctly handled at the moment. In this case one would have to check for collections too.

> Optimize Hibernate for the bulk insertion of related entities
> -------------------------------------------------------------
>
>          Key: HHH-1
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1
>      Project: Hibernate3
>         Type: New Feature

>   Components: core
>  Environment: Hibernate 1.2, MySql 3.1
>     Reporter: Bradley Leupen
>     Priority: Minor

>
>
> It is currently difficult to batch the creation of persistent entities that maintain associations with other entities.
> Add necessary api to hibernate to support the save or update of a collection of entities. An optimization can be applied in this scenario to group inserts / updates by entity class, or table. This will enable the hibernate engine to utilize batching if available, drastically improving performance over a network. 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list