pm.makePersistent(convention2);
pm.currentTransaction().commit();
//set the fetch group to listeIntervenants
FetchPlan fp = pm.getFetchPlan();
fp.clearGroups().addGroup("listeIntervenants");
//detach the intervenant
IntervenantHelper copyOfIntervenant1 = (IntervenantHelper) pm.detachCopy(intervenant1);
assertNotNull(copyOfIntervenant1);
assertEquals("Nomep of intervenant1 and its detached copy are not the same.", intervenant1.getNomep(), copyOfIntervenant1.getNomep());
Collection conv = intervenant1.getConventions();
Collection copyConv = copyOfIntervenant1.getConventions();
assertEquals("Size of conventions not the same for intervenant1 and its detached copy.", conv.size(), copyConv.size());
Iterator itConv = conv.iterator();
Iterator itCopyConv = copyConv.iterator();
while (itConv.hasNext() && itCopyConv.hasNext()) {
ConventionHelper convention = (ConventionHelper) itConv.next();
ConventionHelper copyConvention = (ConventionHelper) itCopyConv.next();
assertEquals("cdmem is not the same for the convention and its detached copy", convention.getCdmem(), copyConvention.getCdmem());
assertEquals("nomep is not the same for the convention and its detached copy", convention.getNomep(), copyConvention.getNomep());
SpecialiteMercureHelper specialiteMercure = convention.getSpecialiteMercure();
SpecialiteMercureHelper copySpecialiteMercure = copyConvention.getSpecialiteMercure();
assertEquals("cdmed not the same for the specialiteMercure and its detached copy", specialiteMercure.getCdmed(), copySpecialiteMercure.getCdmed());
assertEquals("cdmec not the same for the specialiteMercure and its detached copy", specialiteMercure.getCdmec(), copySpecialiteMercure.getCdmec());
assertEquals("cdmese not the same for the specialiteMercure and its detached copy", specialiteMercure.getCdmese(), copySpecialiteMercure.getCdmese());
DomaineHelper domaine = specialiteMercure.getDomaine();
DomaineHelper copyDomaine = copySpecialiteMercure.getDomaine();
assertEquals("cdmed not the same for the domaine and its detached copy", domaine.getCdmed(), copyDomaine.getCdmed());
assertEquals("limed not the same for the domaine and its detached copy", domaine.getLimed(), copyDomaine.getLimed());
MarqueHelper marque = convention.getMarque();
MarqueHelper copyMarque = copyConvention.getMarque();
assertEquals("cdmem is not the same for the marque and its detached copy", marque.getCdmem(), copyMarque.getCdmem());
assertEquals("limem is not the same for the marque and its detached copy", marque.getLimem(), copyMarque.getLimem());
}
//query
Query query = pm.newQuery(ConventionHelper.class);
StringBuffer filter = new StringBuffer();
filter.append("(intervenant.nomep == (\"" +
intervenant1.getNomep() + "\")) && ");
filter.append("(cdmem == (\"" + marque1.getCdmem() + "\"))");
query.setFilter(filter.toString());
//fetchplan
fp = pm.getFetchPlan().clearGroups();
fp.addGroup("listeConventions");
//execute
Collection results = (Collection) query.execute();
//detach all the conventions retrieved
Collection detachedConv = pm.detachCopyAll(results);
Iterator itDC = detachedConv.iterator();