try { em = emf.createEntityManager(); // ... } finally { try { em.close(); } catch (Exception e) { log.error( e ); } }
The try-catch block is not really necessary in tests, neither the logger. The goal here is just to ensure the entity-manager is closed at the end.