detach fix, npe fix i entitymanager