MarqueHelper marque2 = new MarqueHelper();
marque2.setCdmem("2");
marque2.setLimem("marque2");
//create 1 Intervenant
IntervenantHelper intervenant1 = new IntervenantHelper();
intervenant1.setNomep(1);
//create 2 Conventions
ConventionHelper convention1 = new ConventionHelper();
// marque 1 <-> * convention
// intervenant 1 <-> * convention
convention1.setIntervenant(intervenant1);
convention1.setNomep(intervenant1.getNomep());
convention1.setMarque(marque1);
convention1.setCdmem(marque1.getCdmem());
marque1.addConvention(convention1);
intervenant1.addConvention(convention1);
ConventionHelper convention2 = new ConventionHelper();
convention2.setIntervenant(intervenant1);
convention2.setNomep(intervenant1.getNomep());
convention2.setMarque(marque2);
convention2.setCdmem(marque2.getCdmem());
marque2.addConvention(convention2);
intervenant1.addConvention(convention2);
//create 2 communes
CommuneHelper commune1 = new CommuneHelper();
commune1.setId(1);
commune1.setDummy("commune1");
CommuneHelper commune2 = new CommuneHelper();
commune2.setId(2);
commune2.setDummy("commune2");
//create 2 zg
ZoneGeographiqueHelper zg1 = new ZoneGeographiqueHelper();
zg1.setId(1);
// commune 1 <-> * zonegeographique
zg1.setCommune(commune1);
commune1.addZoneGeographique(zg1);
ZoneGeographiqueHelper zg2 = new ZoneGeographiqueHelper();
zg2.setId(2);
// commune 1 <-> * zonegeographique
zg2.setCommune(commune2);
commune2.addZoneGeographique(zg2);
// convention 1 <-> * zonegeographique
convention1.addZoneGeographique(zg1);
zg1.setConvention(convention1);
convention1.addZoneGeographique(zg2);
zg2.setConvention(convention2);
//create a domaine
DomaineHelper domaine1 = new DomaineHelper();
domaine1.setCdmed(1);
domaine1.setLimed(1);
SpecialiteMercureHelper specialiteMercure1 = new SpecialiteMercureHelper();
specialiteMercure1.setCdmec(1);
specialiteMercure1.setCdmed(1);
specialiteMercure1.setCdmese(1);
// spcecialiteMercure * <-> 1 domaine
specialiteMercure1.setDomaine(domaine1);
domaine1.addSpecialiteMercure(specialiteMercure1);
// spcecialiteMercure 1 <-> * convention
specialiteMercure1.addConvention(convention1);
convention1.setSpecialiteMercure(specialiteMercure1);
SpecialiteMercureHelper specialiteMercure2 = new SpecialiteMercureHelper();
specialiteMercure1.setCdmec(2);
specialiteMercure1.setCdmed(1);
specialiteMercure1.setCdmese(2);
// spcecialiteMercure * <-> 1 domaine
specialiteMercure2.setDomaine(domaine1);
domaine1.addSpecialiteMercure(specialiteMercure2);
// spcecialiteMercure 1 <-> * convention
specialiteMercure2.addConvention(convention2);
convention2.setSpecialiteMercure(specialiteMercure2);
PersistenceManager pm = pmf.getPersistenceManager();
try {
pm.currentTransaction().begin();
logger.log(BasicLevel.DEBUG, "make persistent the 2 conventions");
pm.makePersistent(convention1);
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();