private static void updateDependencyCache(
      final JpaDependencyDiagramModel diagramModel,
      final Map<String, Map<String, JpaDependencyType>> jpaDependencyCache,
      final JpaClassModel classModel,
      final String dependentClassName,
      JpaDependencyType dependencyType) {
    // check if the dependent class already has the mapping
    JpaClassModel dependentClass = diagramModel.getClass(dependentClassName);
    Map<String, JpaDependencyType> cache = jpaDependencyCache.get(dependentClassName);
    if (cache != null && dependentClass != null) {
      JpaDependencyType type = cache.get(classModel.getName());
      if (type != null) {
        int result = type.compareTo(dependencyType);
        // check if higher priority JPA mapping already exists between
        // the classes
        if (result < 0 || result == 0 && type != JpaDependencyType.ONE_TO_MANY) {
          return;
        }
        if (result == 0 && type == JpaDependencyType.ONE_TO_MANY) {
          // the one-to-many relationship is present both the sides so
          // convert it to many-to-many
          dependencyType = JpaDependencyType.MANY_TO_MANY;
        }
        // remove entry from the cache and JpaClassModel of the
        // associated class
        cache.remove(classModel.getName());
        dependentClass.removeJpaDependency(classModel.getName());
      }
    }

    // no mapping or lower priority mapping exists between the entities so create new entry in cache
    cache = jpaDependencyCache.get(classModel.getName());
    if (cache == null) {
      cache = new HashMap<String, JpaDependencyType>(3);
    }
    cache.put(dependentClass.getName(), dependencyType);
    classModel.addJpaDependency(dependentClassName, dependencyType);
  }