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

Martin Ross (JIRA) noreply at atlassian.com
Tue Dec 5 01:31:05 EST 2006


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

Martin Ross commented on HHH-1:
-------------------------------

Here is what I have thus far...  There is some other boring code that setups the insertActionMap but it isn't really relevant here...

    public int compareTo(Object other)
    {
        if (other == this)
            return 0;

        if (visited.containsKey(other) && visited.get(other)!=null)
        	return (Integer)visited.get(other);
        else if(visited.containsKey(other) && visited.get(other)==null)
        	return NORESULTYET;
        else
        	// Indicate that we are in the process of currently visiting
        	visited.put(other, null);
        
        final EntityInsertAction otherEntityInsertAction = ((EntityInsertAction) other);
        final Object otherInstance = otherEntityInsertAction.getInstance();
        int result = NORESULTYET;
        if (otherInstance != getInstance())
        {
            // if any of our properties is actually to be inserted, it has to be before us
            for (int i = 0; (result ==NORESULTYET) && i < state.length; i++)
            {
                final Object thisRelation = state[i];
            	if (thisRelation == otherInstance)
            		result = 1;
            	else
            	{
            		// 'this' has a relation to another 'related' object. 'related' must be definitely before 'this'. 
                    EntityInsertAction related = (EntityInsertAction)insertActionMap.get(thisRelation);
                    if (related != null && related!=this) // lets see if other is a parent of related and thus a parent of this
                    {
                    	
                    	// Case 1 - otherEntityInsertAction.compareTo(related) returns 1 => other is a parent of related  => this should return -1 
                    	// Case 2 - otherEntityInsertAction.compareTo(related) returns -1 => other is a child of related => this should return 
                    	// Case 3 - other has no connection to related - related.compareTo should return 0
                    	// In case 2 and 3 we should continue onwards
                    
                    	int recursiveResult = otherEntityInsertAction.compareTo(related);
                    	if (recursiveResult!=NORESULTYET && recursiveResult < 0)
                    		result = -1;
                    } 
            	}
            }
            
            // Check if other has a bidrectional relationship to this
            // Basically the reverse of the previous logic
            for (int i = 0;  (result ==NORESULTYET) && i < otherEntityInsertAction.state.length; i++)
            {
                final Object otherRel = otherEntityInsertAction.state[i];
            	if (otherRel == this.getInstance())
            		result = -1;
            	else
            	{
                    EntityInsertAction related = (EntityInsertAction)insertActionMap.get(otherRel);
                    
                    if (related != null  && related!=this)
                    {
                    	int recursiveResult = this.compareTo(related);
                    	if (recursiveResult!=NORESULTYET && recursiveResult < 0)
                    		result = -1;
                    } 
            	}
            }
        }
        
        if (result==NORESULTYET)
        	result = super.compareTo(other);
    	visited.put(other, Integer.valueOf(result));
        return result;
    } 	


But basically I can't seem to get the recurrence relation to work properly.....
e.g.
                    	if (recursiveResult!=NORESULTYET && recursiveResult < 0)
                    		result = -1;



> 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