Processing forms together for a tree of related entities
This is working now with entity saving logic neatly packaged with the sub-item entity code. Before saving the subitems, I set the value of a hidden element with the parent entity's id. I modified the wrapper form's submit handler array:

    '#submit' =&gt; array(
        'wrapper_form_submit',
        'update_subforms_before_save',
        'subform_submit_all', 
    ),


First, the wrapper is saved and is assigned an id. Then it updates the subforms with that id. And finally the subforms are submitted. The function to update the subforms is modeled after subform_submit_all():

function update_subforms_before_save(&amp;$form, &amp;$form_state) {

    $wrapper_item_id = $form_state['values']['item_id'];

    if (!empty($form_state['temporary']['subform'])) {
        foreach ($form_state['temporary']['subform'] as $subform_name =&gt; &amp;$subform_state) {

            $subform_element = &amp;subform_array_get_nested_value($form, $subform_state['subform_element_parents'], $subform_exists);
            if ($subform_exists) {

                switch($subform_element['#subform_id']) {
                    case 'subitem_entity_form' :
                        $subform_state['values']['parent_item_id'] = $wrapper_item_id;
                        break;
                }

            }
        }
    }
}