Use the entity manager class member instead of global entity manager.