Change from em=null to em.close to close entity manager