// TODO: IS THIS THE RIGHT  WAY TO HANDLE CONCURRENCY?
 public CommunityRun addRunnerToCommunityRun(final String slug, final Profile profile) {
   CommunityRun communityRun = this.findBySlugWithPessimisticWriteLock(slug);
   communityRun.getRunners().add(profile);
   entityManager.merge(communityRun);
   entityManager.flush();
   return communityRun;
 }
 public Set<Profile> allRunners(@NotNull final String slug) {
   CommunityRun communityRun = this.find(slug);
   if (communityRun == null) {
     return emptySet();
   }
   Set<Profile> runners = communityRun.getRunners();
   if (runners.isEmpty()) {
     return emptySet();
   }
   return unmodifiableSet(runners);
 }
 public Set<Profile> findAllRunners(@NotNull final String slug) {
   final String communityRunBySlugQuery = "SELECT cr FROM CommunityRun cr WHERE cr.slug =:slug";
   TypedQuery<CommunityRun> query =
       entityManager
           .createQuery(communityRunBySlugQuery, CommunityRun.class)
           .setParameter("slug", slug);
   try {
     CommunityRun communityRun = query.getSingleResult();
     Set<Profile> profiles = communityRun.getRunners();
     profiles.size();
     return profiles;
   } catch (NoResultException e) {
     throw new NoRecordExistsException(String.format("No community run exists for slug %s", slug));
   }
 }
 public Long save(CommunityRun communityRun) {
   entityManager.persist(communityRun);
   return communityRun.getId();
 }
 public void leaveCommunityRun(final String slug, final Profile profile) {
   CommunityRun communityRun = this.findBySlugWithPessimisticWriteLock(slug);
   communityRun.getRunners().remove(profile);
   entityManager.merge(communityRun);
   entityManager.flush();
 }