### Question:
PersistenceDelegator { public <E> E merge(E e) { if (log.isDebugEnabled()) log.debug("Merging Entity : " + e); if (e == null) { throw new IllegalArgumentException("Entity to be merged must not be null."); } EntityMetadata m = getMetadata(e.getClass()); ObjectGraph graph = new GraphGenerator().generateGraph(e, this); Node node = graph.getHeadNode(); try { lock.writeLock().lock(); node.setPersistenceDelegator(this); node.merge(); flushManager.buildFlushStack(node, EventType.UPDATE); flush(); } finally { lock.writeLock().unlock(); } graph.clear(); graph = null; return (E) node.getData(); } 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 testMerge() { PersonnelDTO dto = new PersonnelDTO(); dto.setPersonId("123"); em.persist(dto); dto = em.find(PersonnelDTO.class, 123); Assert.assertNotNull(dto); dto.setFirstName("kuldeep"); em.merge(dto); dto = em.find(PersonnelDTO.class, 123); Assert.assertNotNull(dto); Assert.assertEquals("kuldeep", dto.getFirstName()); try { em.merge(null); } catch (KunderaException e) { Assert.assertEquals("java.lang.IllegalArgumentException: Entity to be merged must not be null.", e.getMessage()); } try { em.merge(new PersonnelDTO()); } catch (KunderaException e) { Assert.assertEquals("java.lang.IllegalArgumentException: Entity to be persisted can't have Primary key set to null.", e.getMessage()); } }