Reset entity manager when an exception occurs. Better exception handling