Fixed a bug when adding entities to the EntityManager.