public List<Entity> findEntitiesByName(String name) {
   List<Entity> entities = entityDefinitionDao.findEntitiesByName(name);
   for (Entity entity : entities) {
     addToCache(entity);
   }
   return entities;
 }
  /** Will import the entity definition specified in the relative filename of the parameter. */
  public void importEntity(String filename) throws ApplicationException {
    if (filename.isEmpty()) {
      return;
    }

    try {
      File file = new File(filename);
      log.debug("Loading file " + file.getAbsolutePath());
      if (!file.isFile() || !file.canRead()) {
        log.error("Input file is not available.");
        throw new RuntimeException("Input file " + filename + " is not readable.");
      }

      // Import from file
      JAXBContext jaxbContext = JAXBContext.newInstance(EntityModel.class);
      Unmarshaller unJaxbMarshaller = jaxbContext.createUnmarshaller();

      EntityModel entityModel = (EntityModel) unJaxbMarshaller.unmarshal(new FileInputStream(file));

      // convert EntityModel to Entity, EntityAttributeGroups, EntityAttributeValidations
      Entity entity =
          ConvertUtil.mapToEntityModel(entityModel, getEntityAttributeDatatypes(), Entity.class);

      // check existing entity
      List<Entity> entities = entityDefinitionDao.findEntitiesByName(entity.getName());
      for (Entity en : entities) {
        if (en.getVersionId().intValue() == entity.getVersionId().intValue()) {
          log.error("Entity definition already exists: " + entity.getName());
          throw new RuntimeException(
              "Entity definition in the file " + filename + " already exists.");
        }
      }

      // add entity
      Entity newEntity = addEntity(entity);

      // 2. add entity groups with attribute
      List<EntityAttributeGroup> groups =
          ConvertUtil.mapToEntityGroup(
              entityModel, newEntity, org.openhie.openempi.model.EntityAttributeGroup.class);
      for (EntityAttributeGroup group : groups) {
        addEntityAttributeGroup(group);
      }

      // 3. add entity attribute validations
      for (AttributeType attributeType : entityModel.getAttributes().getAttribute()) {
        List<EntityAttributeValidation> validations =
            ConvertUtil.mapToEntityValidations(
                attributeType,
                newEntity,
                org.openhie.openempi.model.EntityAttributeValidation.class);
        for (EntityAttributeValidation validation : validations) {
          addEntityAttributeValidation(validation);
        }
      }
      return;
    } catch (Exception e) {
      log.warn("Unable to Unmarshal xml to a EntityModel: " + e, e);
      throw new RuntimeException(e);
    }
  }