ResourceHostDataService implements DataService<String, ResourceHostEntity> { @Override public synchronized void remove( final String id ) { EntityManager em = emf.createEntityManager(); try { em.getTransaction().begin(); ResourceHostEntity item = em.find( ResourceHostEntity.class, id ); em.remove( item ); em.getTransaction().commit(); } catch ( Exception e ) { LOG.error( e.toString(), e ); if ( em.getTransaction().isActive() ) { em.getTransaction().rollback(); } } finally { em.close(); } } ResourceHostDataService( EntityManagerFactory entityManagerFactory ); @Override synchronized ResourceHostEntity find( final String id ); @Override synchronized Collection<ResourceHostEntity> getAll(); @Override synchronized void persist( final ResourceHostEntity item ); @Override synchronized void remove( final String id ); @Override synchronized void update( ResourceHostEntity item );  }
@Test public void testRemove() throws Exception { service.remove( ID ); verifyCommit(); throwException(); service.remove( ID ); verifyRollback(); }