Better database entity manager handling