Fix infinite loop in UoW with bidirectional inheritance dependencies

This supersedes PR #693. Making `UnitOfWork::getCommitOrder()` consistent with ORM (with minor changes) and removing our recursion of a private method also avoids the infinite loop triggered by #693's test case.

@oparadis: Please let me know if this works for you.