Fix potential NullPointerExceptions in entity managers

If we still have any intermittent NullPointerExceptions in the entity managers, this should fix them.  If not, it should not break anything.