private boolean isFoundInParent(
     String property,
     Object childEntity,
     EntityPersister persister,
     CollectionPersister collectionPersister,
     Object potentialParent) {
   Object collection =
       persister.getPropertyValue(potentialParent, property, session.getEntityMode());
   return collection != null
       && Hibernate.isInitialized(collection)
       && collectionPersister.getCollectionType().contains(collection, childEntity, session);
 }
 private Object getIndexInParent(
     String property,
     Object childEntity,
     EntityPersister persister,
     CollectionPersister collectionPersister,
     Object potentialParent) {
   Object collection =
       persister.getPropertyValue(potentialParent, property, session.getEntityMode());
   if (collection != null && Hibernate.isInitialized(collection)) {
     return collectionPersister.getCollectionType().indexOf(collection, childEntity);
   } else {
     return null;
   }
 }
  private void evictCache(
      Object entity, EntityPersister persister, EventSource session, Object[] oldState) {
    try {
      SessionFactoryImplementor factory = persister.getFactory();

      Set<String> collectionRoles =
          factory.getCollectionRolesByEntityParticipant(persister.getEntityName());
      if (collectionRoles == null || collectionRoles.isEmpty()) {
        return;
      }
      for (String role : collectionRoles) {
        CollectionPersister collectionPersister = factory.getCollectionPersister(role);
        if (!collectionPersister.hasCache()) {
          // ignore collection if no caching is used
          continue;
        }
        // this is the property this OneToMany relation is mapped by
        String mappedBy = collectionPersister.getMappedByProperty();
        if (mappedBy != null) {
          int i = persister.getEntityMetamodel().getPropertyIndex(mappedBy);
          Serializable oldId = null;
          if (oldState != null) {
            // in case of updating an entity we perhaps have to decache 2 entity collections, this
            // is the
            // old one
            oldId = session.getIdentifier(oldState[i]);
          }
          Object ref = persister.getPropertyValue(entity, i);
          Serializable id = null;
          if (ref != null) {
            id = session.getIdentifier(ref);
          }
          // only evict if the related entity has changed
          if (id != null && !id.equals(oldId)) {
            evict(id, collectionPersister, session);
            if (oldId != null) {
              evict(oldId, collectionPersister, session);
            }
          }
        } else {
          LOG.debug("Evict CollectionRegion " + role);
          collectionPersister.getCacheAccessStrategy().evictAll();
        }
      }
    } catch (Exception e) {
      // don't let decaching influence other logic
      LOG.error("", e);
    }
  }