### Question:
PersistenceDelegator { public void detach(Object entity) { Node node = getPersistenceCache().getMainCache().getNodeFromCache(entity, getMetadata(entity.getClass()), this); if (node != null) { node.detach(); } } PersistenceDelegator(final KunderaMetadata kunderaMetadata, final PersistenceCache pc); void persist(Object e); E findById(final Class<E> entityClass, final Object primaryKey); List<E> find(Class<E> entityClass, Object... primaryKeys); List<E> find(Class<E> entityClass, Map<String, String> embeddedColumnMap); void remove(Object e); E merge(E e); void detach(Object entity); Client getClient(EntityMetadata m); Client getClient(final String persistenceUnit); EntityEventDispatcher getEventDispatcher(); boolean isOpen(); void refresh(Object entity); boolean isTransactionInProgress(); PersistenceCache getPersistenceCache(); KunderaMetadata getKunderaMetadata();  }### Answer:
@Test public void testDetach() { PersonnelDTO dto = new PersonnelDTO(); PersistenceDelegator pd = ((EntityManagerImpl) em).getPersistenceDelegator(); try { pd.detach(dto); } catch (IllegalArgumentException e) { Assert.assertEquals("Primary key not set into entity", e.getMessage()); } dto.setPersonId("123"); try { pd.detach(dto); } catch (IllegalArgumentException e) { Assert.fail(); } Assert.assertFalse(pd.contains(dto)); em.persist(dto); pd.detach(dto); Assert.assertFalse(pd.contains(dto)); }