code: boolean contains(Object entity)
      {
          Node node = getPersistenceCache().getMainCache().getNodeFromCache(entity, getMetadata(entity.getClass()), this);
          return node != null && node.isInState(ManagedState.class);
      }
docs: Check if the instance is a managed entity instance belonging to the
  current persistence context.