code: private Entity toEntity(EntityType entityType, Entity emxEntity) {
      Entity entity = entityManager.create(entityType, POPULATE);
      for (Attribute attr : entityType.getAtomicAttributes()) {
        if (attr.getExpression() == null && !attr.isMappedBy()) {
          String attrName = attr.getName();
          Object emxValue = emxEntity.get(attrName);
  
          AttributeType attrType = attr.getDataType();
          switch (attrType) {
            case BOOL:
            case DATE:
            case DATE_TIME:
            case DECIMAL:
            case EMAIL:
            case ENUM:
            case HTML:
            case HYPERLINK:
            case INT:
            case LONG:
            case SCRIPT:
            case STRING:
            case TEXT:
              Object value = emxValue != null ? DataConverter.convert(emxValue, attr) : null;
              if ((!attr.isAuto() || value != null) && (!attr.hasDefaultValue() || value != null)) {
                entity.set(attrName, value);
              }
              break;
            case CATEGORICAL:
            case FILE:
            case XREF:
              // DataConverter.convert performs no conversion for reference types
              Entity refEntity = toRefEntity(attr, emxValue);
  
              // do not set generated auto refEntities to null
              if ((!attr.isAuto() || refEntity != null)
                  && (!attr.hasDefaultValue() || refEntity != null)) {
                entity.set(attrName, refEntity);
              }
              break;
            case CATEGORICAL_MREF:
            case MREF:
              // DataConverter.convert performs no conversion for reference types
              List<Entity> refEntities = toRefEntities(attr, emxValue);
  
              // do not set generated auto refEntities to null
              if (!refEntities.isEmpty()) {
                entity.set(attrName, refEntities);
              }
              break;
            case COMPOUND:
              throw new IllegalAttributeTypeException(attrType);
            default:
              throw new UnexpectedEnumException(attrType);
          }
        }
      }
      return entity;
    }
docs: Create an entity from the EMX entity
  
  @param entityType entity meta data
  @param emxEntity EMX entity
  @return MOLGENIS entity