During sorting of the insert batches, ORM currently only considers the declared entity type of associations for dependencies, which leads to cases where we fail to order correctly and run into constraint violations.