Use transaction for Updating relations

And rollback if deleting or adding a new relation fails.