Fixed problem when deleting detached entity.