Program: 35667
Project: 35667
Buggy source:
@SuppressWarnings("String_Node_Str") public static void persistFlexibleElement(EntityManager em,Mapper mapper,PropertyMap changes,Object model){
  FlexibleElementDTO flexibleEltDTO=null;
  if (changes.get(AdminUtil.PROP_FX_FLEXIBLE_ELEMENT) != null) {
    String name=changes.get(AdminUtil.PROP_FX_NAME);
    ElementTypeEnum type=(ElementTypeEnum)changes.get(AdminUtil.PROP_FX_TYPE);
    Boolean isCompulsory=null;
    if (changes.get(AdminUtil.PROP_FX_IS_COMPULSARY) != null)     isCompulsory=(Boolean)changes.get(AdminUtil.PROP_FX_IS_COMPULSARY);
    PrivacyGroupDTO pg=null;
    if (changes.get(AdminUtil.PROP_FX_PRIVACY_GROUP) != null)     pg=(PrivacyGroupDTO)changes.get(AdminUtil.PROP_FX_PRIVACY_GROUP);
    Boolean amend=null;
    if (changes.get(AdminUtil.PROP_FX_AMENDABLE) != null)     amend=(Boolean)changes.get(AdminUtil.PROP_FX_AMENDABLE);
    LayoutGroupDTO group=null;
    if (changes.get(AdminUtil.PROP_FX_GROUP) != null)     group=(LayoutGroupDTO)changes.get(AdminUtil.PROP_FX_GROUP);
    Integer order=null;
    if (changes.get(AdminUtil.PROP_FX_ORDER_IN_GROUP) != null)     order=(Integer)changes.get(AdminUtil.PROP_FX_ORDER_IN_GROUP);
    Boolean inBanner=null;
    if (changes.get(AdminUtil.PROP_FX_IN_BANNER) != null)     inBanner=(Boolean)changes.get(AdminUtil.PROP_FX_IN_BANNER);
    Integer posB=null;
    if (changes.get(AdminUtil.PROP_FX_POS_IN_BANNER) != null) {
      posB=(Integer)changes.get(AdminUtil.PROP_FX_POS_IN_BANNER);
      posB=posB - 1;
    }
    HashMap<String,Object> oldLayoutFields=(HashMap<String,Object>)changes.get(AdminUtil.PROP_FX_OLD_FIELDS);
    LayoutConstraintDTO oldLayoutConstraintDTO=(LayoutConstraintDTO)oldLayoutFields.get(AdminUtil.PROP_FX_LC);
    LayoutConstraintDTO oldBannerLayoutConstraintDTO=(LayoutConstraintDTO)oldLayoutFields.get(AdminUtil.PROP_FX_LC_BANNER);
    ElementTypeEnum oldType=(ElementTypeEnum)oldLayoutFields.get(AdminUtil.PROP_FX_TYPE);
    Integer oldOrder=(Integer)oldLayoutFields.get(AdminUtil.PROP_FX_ORDER_IN_GROUP);
    Character textType=(Character)changes.get(AdminUtil.PROP_FX_TEXT_TYPE);
    Integer maxLimit=null;
    if (changes.get(AdminUtil.PROP_FX_MAX_LIMIT) != null)     maxLimit=(Integer)changes.get(AdminUtil.PROP_FX_MAX_LIMIT);
    Integer minLimit=null;
    if (changes.get(AdminUtil.PROP_FX_MIN_LIMIT) != null)     minLimit=(Integer)changes.get(AdminUtil.PROP_FX_MIN_LIMIT);
    Integer length=null;
    if (changes.get(AdminUtil.PROP_FX_LENGTH) != null)     length=(Integer)changes.get(AdminUtil.PROP_FX_LENGTH);
    Boolean decimal=null;
    if (changes.get(AdminUtil.PROP_FX_DECIMAL) != null)     decimal=(Boolean)changes.get(AdminUtil.PROP_FX_DECIMAL);
    ReportModelDTO reportModel=null;
    if (changes.get(AdminUtil.PROP_FX_REPORT_MODEL) != null)     reportModel=(ReportModelDTO)changes.get(AdminUtil.PROP_FX_REPORT_MODEL);
    Boolean isMultiple=null;
    if (changes.get(AdminUtil.PROP_FX_Q_MULTIPLE) != null)     isMultiple=(Boolean)changes.get(AdminUtil.PROP_FX_Q_MULTIPLE);
    CategoryTypeDTO category=null;
    if (changes.get(AdminUtil.PROP_FX_Q_CATEGORY) != null)     category=(CategoryTypeDTO)changes.get(AdminUtil.PROP_FX_Q_CATEGORY);
    List<String> qChoices=null;
    if (changes.get(AdminUtil.PROP_FX_Q_CHOICES) != null)     qChoices=(List<String>)changes.get(AdminUtil.PROP_FX_Q_CHOICES);
    flexibleEltDTO=(FlexibleElementDTO)changes.get(AdminUtil.PROP_FX_FLEXIBLE_ELEMENT);
    FlexibleElement flexibleElt=null;
    if (flexibleEltDTO.getId() != 0) {
      flexibleElt=em.find(FlexibleElement.class,new Integer(flexibleEltDTO.getId()).longValue());
    }
 else {
      flexibleElt=(FlexibleElement)createNewFlexibleElement(em,oldType,type,flexibleElt);
    }
    log.debug("String_Node_Str" + name + "String_Node_Str"+ type+ "String_Node_Str"+ group+ "String_Node_Str"+ order+ "String_Node_Str"+ inBanner+ "String_Node_Str"+ posB+ "String_Node_Str"+ isCompulsory+ "String_Node_Str"+ pg+ "String_Node_Str"+ amend+ "String_Node_Str");
    log.debug("String_Node_Str" + maxLimit + "String_Node_Str"+ minLimit+ "String_Node_Str"+ textType+ "String_Node_Str"+ length+ "String_Node_Str"+ decimal+ "String_Node_Str"+ reportModel+ "String_Node_Str");
    Boolean basicChanges=false;
    if (flexibleElt != null) {
      if (name != null) {
        flexibleElt.setLabel(name);
        basicChanges=true;
      }
      if (amend != null) {
        flexibleElt.setAmendable(amend);
        basicChanges=true;
      }
      if (isCompulsory != null) {
        flexibleElt.setValidates(isCompulsory);
        basicChanges=true;
      }
      if (pg != null) {
        PrivacyGroup pgToPersist=em.find(PrivacyGroup.class,pg.getId());
        if (pgToPersist != null) {
          flexibleElt.setPrivacyGroup(pgToPersist);
          basicChanges=true;
        }
      }
      if (basicChanges && flexibleElt.getId() != null)       flexibleElt=em.merge(flexibleElt);
 else       em.persist(flexibleElt);
    }
    if (group != null) {
      LayoutGroup parentLayoutGroup=em.find(LayoutGroup.class,new Integer(group.getId()).longValue());
      LayoutConstraint newLayoutConstraint=new LayoutConstraint();
      if (parentLayoutGroup != null) {
        newLayoutConstraint.setElement(flexibleElt);
        newLayoutConstraint.setParentLayoutGroup(parentLayoutGroup);
        if (order != null)         newLayoutConstraint.setSortOrder(order);
        if (oldOrder != null)         newLayoutConstraint.setSortOrder(oldOrder);
        if (order == null && oldOrder == null)         newLayoutConstraint.setSortOrder(new Integer(parentLayoutGroup.getConstraints().size()));
        if (oldLayoutConstraintDTO != null) {
          newLayoutConstraint.setId(new Integer(oldLayoutConstraintDTO.getId()).longValue());
          newLayoutConstraint=em.merge(newLayoutConstraint);
        }
 else {
          em.persist(newLayoutConstraint);
        }
      }
    }
    if (inBanner != null) {
      if (inBanner) {
        if (model instanceof ProjectModel)         changeBanner(em,posB,(ProjectModel)model,flexibleElt);
 else         if (model instanceof OrgUnitModel)         changeBanner(em,posB,(OrgUnitModel)model,flexibleElt);
      }
 else {
        if (oldBannerLayoutConstraintDTO != null) {
          LayoutConstraint oldBannerLayoutConstraint=mapper.map(oldBannerLayoutConstraintDTO,LayoutConstraint.class);
          oldBannerLayoutConstraint=em.find(LayoutConstraint.class,oldBannerLayoutConstraint.getId());
          em.remove(oldBannerLayoutConstraint);
        }
      }
    }
 else {
      if (posB != null) {
        LayoutConstraint oldBannerLayoutConstraint=mapper.map(oldBannerLayoutConstraintDTO,LayoutConstraint.class);
        if (model instanceof ProjectModel)         changePositionInBanner(em,posB,(ProjectModel)model,flexibleElt,oldBannerLayoutConstraint);
 else         if (model instanceof OrgUnitModel)         changePositionInBanner(em,posB,(OrgUnitModel)model,flexibleElt,oldBannerLayoutConstraint);
      }
    }
    if (oldType != null && type != null) {
      flexibleElt=(FlexibleElement)createNewFlexibleElement(em,oldType,type,flexibleElt);
      log.debug("String_Node_Str" + flexibleElt.getClass());
    }
    em.flush();
    em.clear();
    flexibleElt=em.find(FlexibleElement.class,flexibleElt.getId());
    Boolean specificChanges=false;
    if (ElementTypeEnum.FILES_LIST.equals(type) || (ElementTypeEnum.FILES_LIST.equals(oldType) && type == null)) {
      FilesListElement filesListElement=(FilesListElement)flexibleElt;
      if (filesListElement != null) {
        if (maxLimit != null) {
          filesListElement.setLimit(maxLimit);
          specificChanges=true;
        }
        if (specificChanges) {
          filesListElement=em.merge(filesListElement);
          flexibleElt=filesListElement;
        }
      }
    }
 else     if (ElementTypeEnum.TEXT_AREA.equals(type) || (ElementTypeEnum.TEXT_AREA.equals(oldType) && type == null)) {
      TextAreaElement textAreaElement=(TextAreaElement)flexibleElt;
      if (textAreaElement != null) {
        if (maxLimit != null) {
          ((TextAreaElement)flexibleElt).setMaxValue(new Integer(maxLimit).longValue());
          specificChanges=true;
        }
        if (minLimit != null) {
          ((TextAreaElement)flexibleElt).setMinValue(new Integer(minLimit).longValue());
          specificChanges=true;
        }
        if (length != null) {
          ((TextAreaElement)flexibleElt).setLength(length);
          specificChanges=true;
        }
        if (decimal != null) {
          ((TextAreaElement)flexibleElt).setIsDecimal(decimal);
          specificChanges=true;
        }
        if (textType != null) {
          ((TextAreaElement)flexibleElt).setType(textType);
          specificChanges=true;
        }
        if (specificChanges) {
          flexibleElt=em.merge((TextAreaElement)flexibleElt);
        }
      }
    }
 else     if (ElementTypeEnum.REPORT.equals(type) || (ElementTypeEnum.REPORT.equals(oldType) && type == null)) {
      ReportElement reportElement=em.find(ReportElement.class,flexibleElt.getId());
      if (reportElement != null) {
        if (reportModel != null) {
          if (reportModel.getName() != null) {
            Integer reportId=findIdForReport(em,reportModel.getName());
            ((ReportElement)flexibleElt).setModelId(reportId);
            specificChanges=true;
          }
        }
        if (specificChanges) {
          flexibleElt=em.merge((ReportElement)flexibleElt);
        }
      }
    }
 else     if (ElementTypeEnum.REPORT_LIST.equals(type) || (ElementTypeEnum.REPORT_LIST.equals(oldType) && type == null)) {
      ReportListElement reportElement=em.find(ReportListElement.class,flexibleElt.getId());
      if (reportElement != null) {
        if (reportModel.getName() != null) {
          Integer reportId=findIdForReport(em,reportModel.getName());
          ((ReportListElement)flexibleElt).setModelId(reportId);
          specificChanges=true;
        }
        if (specificChanges) {
          flexibleElt=em.merge((ReportListElement)flexibleElt);
        }
      }
    }
 else     if (ElementTypeEnum.QUESTION.equals(type) || (ElementTypeEnum.QUESTION.equals(oldType) && type == null)) {
      QuestionElement questionElement=em.find(QuestionElement.class,flexibleElt.getId());
      if (questionElement != null) {
        if (isMultiple != null) {
          ((QuestionElement)flexibleElt).setIsMultiple(isMultiple);
          specificChanges=true;
        }
        if (category != null) {
          for (          QuestionChoiceElement choiceElt : ((QuestionElement)flexibleElt).getChoices()) {
            em.remove(choiceElt);
          }
          CategoryType categoryType=em.find(CategoryType.class,category.getId());
          if (categoryType != null) {
            ((QuestionElement)flexibleElt).setCategoryType(categoryType);
            List<QuestionChoiceElement> choices=new ArrayList<QuestionChoiceElement>();
            int i=0;
            for (            CategoryElement catElt : categoryType.getElements()) {
              QuestionChoiceElement qChoice=new QuestionChoiceElement();
              qChoice.setLabel("String_Node_Str");
              qChoice.setCategoryElement(catElt);
              qChoice.setParentQuestion(questionElement);
              qChoice.setSortOrder(i++);
              choices.add(qChoice);
            }
            ((QuestionElement)flexibleElt).setChoices(choices);
            specificChanges=true;
          }
        }
 else         if (qChoices != null) {
          for (          QuestionChoiceElement choiceElt : ((QuestionElement)flexibleElt).getChoices()) {
            em.remove(choiceElt);
          }
          ((QuestionElement)flexibleElt).setCategoryType(null);
          List<QuestionChoiceElement> choices=new ArrayList<QuestionChoiceElement>();
          int i=0;
          for (          String choiceLabel : qChoices) {
            QuestionChoiceElement qChoice=new QuestionChoiceElement();
            qChoice.setLabel(choiceLabel);
            qChoice.setParentQuestion(questionElement);
            qChoice.setSortOrder(i++);
            choices.add(qChoice);
          }
          ((QuestionElement)flexibleElt).setChoices(choices);
          specificChanges=true;
        }
        if (specificChanges) {
          flexibleElt=em.merge((QuestionElement)flexibleElt);
        }
      }
    }
    em.flush();
    em.clear();
  }
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public static void persistFlexibleElement(EntityManager em,Mapper mapper,PropertyMap changes,Object model){
  FlexibleElementDTO flexibleEltDTO=null;
  if (changes.get(AdminUtil.PROP_FX_FLEXIBLE_ELEMENT) != null) {
    String name=changes.get(AdminUtil.PROP_FX_NAME);
    ElementTypeEnum type=(ElementTypeEnum)changes.get(AdminUtil.PROP_FX_TYPE);
    Boolean isCompulsory=null;
    if (changes.get(AdminUtil.PROP_FX_IS_COMPULSARY) != null)     isCompulsory=(Boolean)changes.get(AdminUtil.PROP_FX_IS_COMPULSARY);
    PrivacyGroupDTO pg=null;
    if (changes.get(AdminUtil.PROP_FX_PRIVACY_GROUP) != null)     pg=(PrivacyGroupDTO)changes.get(AdminUtil.PROP_FX_PRIVACY_GROUP);
    Boolean amend=null;
    if (changes.get(AdminUtil.PROP_FX_AMENDABLE) != null)     amend=(Boolean)changes.get(AdminUtil.PROP_FX_AMENDABLE);
    LayoutGroupDTO group=null;
    if (changes.get(AdminUtil.PROP_FX_GROUP) != null)     group=(LayoutGroupDTO)changes.get(AdminUtil.PROP_FX_GROUP);
    Integer order=null;
    if (changes.get(AdminUtil.PROP_FX_ORDER_IN_GROUP) != null)     order=(Integer)changes.get(AdminUtil.PROP_FX_ORDER_IN_GROUP);
    Boolean inBanner=null;
    if (changes.get(AdminUtil.PROP_FX_IN_BANNER) != null)     inBanner=(Boolean)changes.get(AdminUtil.PROP_FX_IN_BANNER);
    Integer posB=null;
    if (changes.get(AdminUtil.PROP_FX_POS_IN_BANNER) != null) {
      posB=(Integer)changes.get(AdminUtil.PROP_FX_POS_IN_BANNER);
      posB=posB - 1;
    }
    HashMap<String,Object> oldLayoutFields=(HashMap<String,Object>)changes.get(AdminUtil.PROP_FX_OLD_FIELDS);
    LayoutConstraintDTO oldLayoutConstraintDTO=(LayoutConstraintDTO)oldLayoutFields.get(AdminUtil.PROP_FX_LC);
    LayoutConstraintDTO oldBannerLayoutConstraintDTO=(LayoutConstraintDTO)oldLayoutFields.get(AdminUtil.PROP_FX_LC_BANNER);
    ElementTypeEnum oldType=(ElementTypeEnum)oldLayoutFields.get(AdminUtil.PROP_FX_TYPE);
    Integer oldOrder=(Integer)oldLayoutFields.get(AdminUtil.PROP_FX_ORDER_IN_GROUP);
    Character textType=(Character)changes.get(AdminUtil.PROP_FX_TEXT_TYPE);
    Integer maxLimit=null;
    if (changes.get(AdminUtil.PROP_FX_MAX_LIMIT) != null)     maxLimit=(Integer)changes.get(AdminUtil.PROP_FX_MAX_LIMIT);
    Integer minLimit=null;
    if (changes.get(AdminUtil.PROP_FX_MIN_LIMIT) != null)     minLimit=(Integer)changes.get(AdminUtil.PROP_FX_MIN_LIMIT);
    Integer length=null;
    if (changes.get(AdminUtil.PROP_FX_LENGTH) != null)     length=(Integer)changes.get(AdminUtil.PROP_FX_LENGTH);
    Boolean decimal=null;
    if (changes.get(AdminUtil.PROP_FX_DECIMAL) != null)     decimal=(Boolean)changes.get(AdminUtil.PROP_FX_DECIMAL);
    ReportModelDTO reportModel=null;
    if (changes.get(AdminUtil.PROP_FX_REPORT_MODEL) != null)     reportModel=(ReportModelDTO)changes.get(AdminUtil.PROP_FX_REPORT_MODEL);
    Boolean isMultiple=null;
    if (changes.get(AdminUtil.PROP_FX_Q_MULTIPLE) != null)     isMultiple=(Boolean)changes.get(AdminUtil.PROP_FX_Q_MULTIPLE);
    CategoryTypeDTO category=null;
    if (changes.get(AdminUtil.PROP_FX_Q_CATEGORY) != null)     category=(CategoryTypeDTO)changes.get(AdminUtil.PROP_FX_Q_CATEGORY);
    List<String> qChoices=null;
    if (changes.get(AdminUtil.PROP_FX_Q_CHOICES) != null)     qChoices=(List<String>)changes.get(AdminUtil.PROP_FX_Q_CHOICES);
    flexibleEltDTO=(FlexibleElementDTO)changes.get(AdminUtil.PROP_FX_FLEXIBLE_ELEMENT);
    FlexibleElement flexibleElt=null;
    if (flexibleEltDTO.getId() != 0) {
      flexibleElt=em.find(FlexibleElement.class,new Integer(flexibleEltDTO.getId()).longValue());
    }
 else {
      flexibleElt=(FlexibleElement)createNewFlexibleElement(em,oldType,type,flexibleElt);
    }
    log.debug("String_Node_Str" + name + "String_Node_Str"+ type+ "String_Node_Str"+ group+ "String_Node_Str"+ order+ "String_Node_Str"+ inBanner+ "String_Node_Str"+ posB+ "String_Node_Str"+ isCompulsory+ "String_Node_Str"+ pg+ "String_Node_Str"+ amend+ "String_Node_Str");
    log.debug("String_Node_Str" + maxLimit + "String_Node_Str"+ minLimit+ "String_Node_Str"+ textType+ "String_Node_Str"+ length+ "String_Node_Str"+ decimal+ "String_Node_Str"+ reportModel+ "String_Node_Str");
    Boolean basicChanges=false;
    if (flexibleElt != null) {
      if (name != null) {
        flexibleElt.setLabel(name);
        basicChanges=true;
      }
      if (amend != null) {
        flexibleElt.setAmendable(amend);
        basicChanges=true;
      }
      if (isCompulsory != null) {
        flexibleElt.setValidates(isCompulsory);
        basicChanges=true;
      }
      if (pg != null) {
        PrivacyGroup pgToPersist=em.find(PrivacyGroup.class,pg.getId());
        if (pgToPersist != null) {
          flexibleElt.setPrivacyGroup(pgToPersist);
          basicChanges=true;
        }
      }
      if (basicChanges && flexibleElt.getId() != null)       flexibleElt=em.merge(flexibleElt);
 else       em.persist(flexibleElt);
    }
    if (group != null) {
      LayoutGroup parentLayoutGroup=em.find(LayoutGroup.class,new Integer(group.getId()).longValue());
      LayoutConstraint newLayoutConstraint=new LayoutConstraint();
      if (parentLayoutGroup != null) {
        newLayoutConstraint.setElement(flexibleElt);
        newLayoutConstraint.setParentLayoutGroup(parentLayoutGroup);
        if (oldOrder != null)         newLayoutConstraint.setSortOrder(oldOrder);
        if (order != null)         newLayoutConstraint.setSortOrder(order);
        if (order == null && oldOrder == null)         newLayoutConstraint.setSortOrder(new Integer(parentLayoutGroup.getConstraints().size()));
        if (oldLayoutConstraintDTO != null) {
          newLayoutConstraint.setId(new Integer(oldLayoutConstraintDTO.getId()).longValue());
          newLayoutConstraint=em.merge(newLayoutConstraint);
        }
 else {
          em.persist(newLayoutConstraint);
        }
      }
    }
    if (inBanner != null) {
      if (inBanner) {
        if (model instanceof ProjectModel)         changeBanner(em,posB,(ProjectModel)model,flexibleElt);
 else         if (model instanceof OrgUnitModel)         changeBanner(em,posB,(OrgUnitModel)model,flexibleElt);
      }
 else {
        if (oldBannerLayoutConstraintDTO != null) {
          LayoutConstraint oldBannerLayoutConstraint=mapper.map(oldBannerLayoutConstraintDTO,LayoutConstraint.class);
          oldBannerLayoutConstraint=em.find(LayoutConstraint.class,oldBannerLayoutConstraint.getId());
          em.remove(oldBannerLayoutConstraint);
        }
      }
    }
 else {
      if (posB != null) {
        LayoutConstraint oldBannerLayoutConstraint=mapper.map(oldBannerLayoutConstraintDTO,LayoutConstraint.class);
        if (model instanceof ProjectModel)         changePositionInBanner(em,posB,(ProjectModel)model,flexibleElt,oldBannerLayoutConstraint);
 else         if (model instanceof OrgUnitModel)         changePositionInBanner(em,posB,(OrgUnitModel)model,flexibleElt,oldBannerLayoutConstraint);
      }
    }
    if (oldType != null && type != null) {
      flexibleElt=(FlexibleElement)createNewFlexibleElement(em,oldType,type,flexibleElt);
      log.debug("String_Node_Str" + flexibleElt.getClass());
    }
    em.flush();
    em.clear();
    flexibleElt=em.find(FlexibleElement.class,flexibleElt.getId());
    Boolean specificChanges=false;
    if (ElementTypeEnum.FILES_LIST.equals(type) || (ElementTypeEnum.FILES_LIST.equals(oldType) && type == null)) {
      FilesListElement filesListElement=(FilesListElement)flexibleElt;
      if (filesListElement != null) {
        if (maxLimit != null) {
          filesListElement.setLimit(maxLimit);
          specificChanges=true;
        }
        if (specificChanges) {
          filesListElement=em.merge(filesListElement);
          flexibleElt=filesListElement;
        }
      }
    }
 else     if (ElementTypeEnum.TEXT_AREA.equals(type) || (ElementTypeEnum.TEXT_AREA.equals(oldType) && type == null)) {
      TextAreaElement textAreaElement=(TextAreaElement)flexibleElt;
      if (textAreaElement != null) {
        if (maxLimit != null) {
          ((TextAreaElement)flexibleElt).setMaxValue(new Integer(maxLimit).longValue());
          specificChanges=true;
        }
        if (minLimit != null) {
          ((TextAreaElement)flexibleElt).setMinValue(new Integer(minLimit).longValue());
          specificChanges=true;
        }
        if (length != null) {
          ((TextAreaElement)flexibleElt).setLength(length);
          specificChanges=true;
        }
        if (decimal != null) {
          ((TextAreaElement)flexibleElt).setIsDecimal(decimal);
          specificChanges=true;
        }
        if (textType != null) {
          ((TextAreaElement)flexibleElt).setType(textType);
          specificChanges=true;
        }
        if (specificChanges) {
          flexibleElt=em.merge((TextAreaElement)flexibleElt);
        }
      }
    }
 else     if (ElementTypeEnum.REPORT.equals(type) || (ElementTypeEnum.REPORT.equals(oldType) && type == null)) {
      ReportElement reportElement=em.find(ReportElement.class,flexibleElt.getId());
      if (reportElement != null) {
        if (reportModel != null) {
          if (reportModel.getName() != null) {
            Integer reportId=findIdForReport(em,reportModel.getName());
            ((ReportElement)flexibleElt).setModelId(reportId);
            specificChanges=true;
          }
        }
        if (specificChanges) {
          flexibleElt=em.merge((ReportElement)flexibleElt);
        }
      }
    }
 else     if (ElementTypeEnum.REPORT_LIST.equals(type) || (ElementTypeEnum.REPORT_LIST.equals(oldType) && type == null)) {
      ReportListElement reportElement=em.find(ReportListElement.class,flexibleElt.getId());
      if (reportElement != null) {
        if (reportModel.getName() != null) {
          Integer reportId=findIdForReport(em,reportModel.getName());
          ((ReportListElement)flexibleElt).setModelId(reportId);
          specificChanges=true;
        }
        if (specificChanges) {
          flexibleElt=em.merge((ReportListElement)flexibleElt);
        }
      }
    }
 else     if (ElementTypeEnum.QUESTION.equals(type) || (ElementTypeEnum.QUESTION.equals(oldType) && type == null)) {
      QuestionElement questionElement=em.find(QuestionElement.class,flexibleElt.getId());
      if (questionElement != null) {
        if (isMultiple != null) {
          ((QuestionElement)flexibleElt).setIsMultiple(isMultiple);
          specificChanges=true;
        }
        if (category != null) {
          for (          QuestionChoiceElement choiceElt : ((QuestionElement)flexibleElt).getChoices()) {
            em.remove(choiceElt);
          }
          CategoryType categoryType=em.find(CategoryType.class,category.getId());
          if (categoryType != null) {
            ((QuestionElement)flexibleElt).setCategoryType(categoryType);
            List<QuestionChoiceElement> choices=new ArrayList<QuestionChoiceElement>();
            int i=0;
            for (            CategoryElement catElt : categoryType.getElements()) {
              QuestionChoiceElement qChoice=new QuestionChoiceElement();
              qChoice.setLabel("String_Node_Str");
              qChoice.setCategoryElement(catElt);
              qChoice.setParentQuestion(questionElement);
              qChoice.setSortOrder(i++);
              choices.add(qChoice);
            }
            ((QuestionElement)flexibleElt).setChoices(choices);
            specificChanges=true;
          }
        }
 else         if (qChoices != null) {
          for (          QuestionChoiceElement choiceElt : ((QuestionElement)flexibleElt).getChoices()) {
            em.remove(choiceElt);
          }
          ((QuestionElement)flexibleElt).setCategoryType(null);
          List<QuestionChoiceElement> choices=new ArrayList<QuestionChoiceElement>();
          int i=0;
          for (          String choiceLabel : qChoices) {
            QuestionChoiceElement qChoice=new QuestionChoiceElement();
            qChoice.setLabel(choiceLabel);
            qChoice.setParentQuestion(questionElement);
            qChoice.setSortOrder(i++);
            choices.add(qChoice);
          }
          ((QuestionElement)flexibleElt).setChoices(choices);
          specificChanges=true;
        }
        if (specificChanges) {
          flexibleElt=em.merge((QuestionElement)flexibleElt);
        }
      }
    }
    em.flush();
    em.clear();
  }
}