Impex with Ordered Relations in a Multithreaded Mode

Keeping the order for an ordered relation is crucial while impexing changes, or exporting and importing items between environments. The ordering.attribute property allows you to keep a correct order of items of an ordered relation while using impex in a multithreaded mode.

One-to-Many Relation

With one-to-many relations, where the many part should have a particular order, impex executed in a multithreaded mode doesn't provide a correct result. The lines are executed in a random order and the order is lost.

To keep the correct order when using impex, add ordering.attribute in items.xml for a given relation, and expose that attribute in the many item. Here is how ordering.attribute is defined out-of-the-box for the AbstractOrder2AbstractOrderEntry relation:

<relation code="AbstractOrder2AbstractOrderEntry" localized="false" generate="true" autocreate="true">
            <sourceElement type="AbstractOrder" qualifier="order" cardinality="one">
                <modifiers read="true" write="true" search="true" optional="true"/>
                <custom-properties>
                    <property name="ordering.attribute">
                        <value>"entryNumber"</value>
                    </property>
                </custom-properties>
            </sourceElement>
            <targetElement type="AbstractOrderEntry" qualifier="entries" cardinality="many" collectiontype="list"
                           ordered="false">
                <modifiers read="true" write="true" search="true" optional="true" partof="true"/>
                <custom-properties>
                    <property name="query.filter">
                        <value>"{original} is null"</value>
                    </property>
                </custom-properties>
            </targetElement>
        </relation>
                ...
                ...
                ...
 
<attribute autocreate="true" qualifier="entryNumber" type="java.lang.Integer" generate="true">
     <defaultvalue>Integer.valueOf(de.hybris.platform.jalo.order.AbstractOrder.APPEND_AS_LAST)
     </defaultvalue>
     <persistence type="property"/>
     <modifiers read="true" write="true" search="true" optional="true" unique="true"/>
     </attribute>

Adding these settings afterwards works fine on condition you use the same column name as in the original deployment. If you start from scratch, and the item was never released to production and no data exists, then you can choose your own name for the ordering.attribute value.

With those settings in place, you can add your new ordering column to your impex, as well as numbers for order, and it doesn't matter anymore in which order the impex lines are executed by a multi-threaded executor.