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

Michael Kopp (JIRA) noreply at atlassian.com
Thu Oct 12 01:47:26 EDT 2006


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

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

HI Martin,

I hadn't had the time to do that patch. or better I hadn't had the time to properly test and submit it. maybe you can do that.

All you have to do is to add the following to the EntitiyInsertAction

    public int compareTo(Object other)
    {
        if (other == this)
            return 0;
        try
        {
            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
                for (int i = 0; i < state.length; i++)
                {
                    final Object rel = state[i];
                    if (rel == instance)
                        return +1; // the 'other' InsertAction inserts something that we need. it has to be before us in the queue
                }
            }
        } catch (ClassCastException e)
        {
            // why would we compare against another object than one with the same type...
        }
        return super.compareTo(other);
    }

It makes sure that (upon sorting) an instance gets always inserted before the referal to that instance.
After that you just have to sort the inserts like hibernate sorts the updates (can be configured)

e.g. change the ActionQueue.sortUpdateActions and add a sort for the inserts.

That should do it.


> 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