Fix bug in getting entity manager