entity manager initialisation and cleanup