title: adding excerpt projection to spring data rest repository causes stack overflow error
body: <p>We are facing <code>StackoverflowError</code> when we enable an except projection on a REST repository. The entity is question has two associations, a <code>@ManyToOne</code> with one <code>Venue</code> entity that has to be included inline for all responses, and a <code>@OneToMany</code> with <code>Trainee</code> entity we always want to hide. The entity (relevant) snippet</p>
  
  <pre><code>@Entity
  @EntityListeners(AuditingEntityListener.class)
  public class Workshop implements Serializable {
  
    private static final long serialVersionUID = -5516160437873476233L;
  
    private Long id;
  
    // omitted properties
  
    private Venue venue;
  
    private Set&lt;Trainee&gt; trainees;
  
    @Id
    @GeneratedValue
    public Long getId() {
      return id;
    }
  
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinTable(name = "workshop_venue", joinColumns = { @JoinColumn(name = "workshop_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "venue_id", referencedColumnName = "id") })
    public Venue getVenue() {
      return venue;
    }
  
    @OneToMany
    @JoinTable(name = "workshop_trainees", joinColumns = { @JoinColumn(name = "workshiop_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "trainee_id", referencedColumnName = "email") })
    @RestResource(exported = false)
    @JsonIgnore
    public Set&lt;Trainee&gt; getTrainees() {
      return trainees;
    }
  
    // omitted getters/setters
  }
  </code></pre>
  
  <p>when I add this Projection</p>
  
  <pre><code>@Projection(name = "default", types = { Workshop.class })
  public interface InlineVenueProjection {
  
    String getName();
  
    Integer getSeatsAvailable();
  
    WorkshopType getWorkshopType();
  
    Date getDate();
  
    Venue getVenue();
  }
  </code></pre>
  
  <p>and enable it in the repository</p>
  
  <pre><code>@RepositoryRestResource(collectionResourceRel = "workshop", path = "workshops", excerptProjection = InlineVenueProjection.class)
  public interface WorkshopRepository extends JpaRepository&lt;Workshop, Long&gt; {
  // omitted methods
  }
  </code></pre>
  
  <p>I get a stack overflow error in POST requests </p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.StackOverflowError
  </code></pre>
  
  <p>and further in the stack trace </p>
  
  <pre><code>Caused by: java.lang.StackOverflowError: null
      at java.util.concurrent.locks.ReentrantReadWriteLock$Sync$ThreadLocalHoldCounter.initialValue(ReentrantReadWriteLock.java:286)
      at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:180)
      at java.lang.ThreadLocal.get(ThreadLocal.java:170)
      at java.util.concurrent.locks.ReentrantReadWriteLock$Sync.tryReleaseShared(ReentrantReadWriteLock.java:423)
      at java.util.concurrent.locks.AbstractQueuedSynchronizer.releaseShared(AbstractQueuedSynchronizer.java:1341)
      at java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock.unlock(ReentrantReadWriteLock.java:881)
      at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:169)
      at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:140)
      at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:67)
      at org.springframework.data.mapping.context.PersistentEntities.getPersistentEntity(PersistentEntities.java:63)
      at org.springframework.data.rest.webmvc.mapping.LinkCollectingAssociationHandler.doWithAssociation(LinkCollectingAssociationHandler.java:100)
      at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:352)
  </code></pre>