From: Michael K. (JIRA) <no...@at...> - 2006-04-28 18:12:36
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1?page=comments#action_22901 ] Michael Kopp commented on HHH-1: -------------------------------- Ok I have it and It is actually so simple its real beautiful. All we need is to override the compare method in EntityInsertAction: public int compareTo(Object other) { if (other == this) // always equal return 0; try { final EntityInsertAction entityInsertAction = ((EntityInsertAction) other); final Object instance = entityInsertAction.getInstance(); if (instance != getInstance()) // just to prevent checking on duplicate insert { // 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 != null && rel == instance) return +1; } } } catch (ClassCastException e) { // why would we compare against another object than one with the same type... // but let that be here to catch that off case } // the base compare, sorts first by roleName which effectifly groups the statements by the tables affected return super.compareTo(other); } And then add an option to sort the inserts, like it already exists for updates. This way it cannot have any effect on existing configuration, you actually have to choose it. What it does is: if the entity of the other Action is actually referenced in one of the properties, that other action needs to come first (as they are both inserts). if not we just sort it like updates, which results in grouping by tables. It minimizes the roundtrips to the minimum, exactly like the updates sort does too. Max do you think this change could make it into 3.2, it is a very small change and has no effect if not explicitly turned on. > 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 |