Fixed bug in EntityManager