Deadlock prevention by ordering the DB elements