private String getMappedBy(Collection collectionValue) {
    PersistentClass referencedClass = null;
    if (collectionValue.getElement() instanceof OneToMany) {
      OneToMany oneToManyValue = (OneToMany) collectionValue.getElement();
      referencedClass = oneToManyValue.getAssociatedClass();
    } else if (collectionValue.getElement() instanceof ManyToOne) {
      // Case for bi-directional relation with @JoinTable on the owning @ManyToOne side.
      ManyToOne manyToOneValue = (ManyToOne) collectionValue.getElement();
      referencedClass =
          manyToOneValue.getMappings().getClass(manyToOneValue.getReferencedEntityName());
    }

    // If there's an @AuditMappedBy specified, returning it directly.
    String auditMappedBy = propertyAuditingData.getAuditMappedBy();
    if (auditMappedBy != null) {
      return auditMappedBy;
    }

    // searching in referenced class
    String mappedBy = this.searchMappedBy(referencedClass, collectionValue);

    if (mappedBy == null) {
      LOG.debugf(
          "Going to search the mapped by attribute for %s in superclasses of entity: %s",
          propertyName, referencedClass.getClassName());

      PersistentClass tempClass = referencedClass;
      while ((mappedBy == null) && (tempClass.getSuperclass() != null)) {
        LOG.debugf("Searching in superclass: %s", tempClass.getSuperclass().getClassName());
        mappedBy = this.searchMappedBy(tempClass.getSuperclass(), collectionValue);
        tempClass = tempClass.getSuperclass();
      }
    }

    if (mappedBy == null) {
      throw new MappingException(
          "Unable to read the mapped by attribute for "
              + propertyName
              + " in "
              + referencedClass.getClassName()
              + "!");
    }

    return mappedBy;
  }