title: HashCode Loop Calling : OneToMany JPA
body: <p>I want to excute this method : </p>
  
  <pre><code>@RequestMapping(value = "/list", method = RequestMethod.GET)
  public List&lt;Project&gt; listProjects() {
  
      return ps.findAllProjects();
  }
  </code></pre>
  
  <p>And in my <strong>DAO</strong> I have : </p>
  
  <pre><code>@Repository
  public interface ProjectDAO extends JpaRepository&lt;Project, Long&gt; {
      List&lt;Project&gt; findAllProjectsByShowableTrue();  }
  </code></pre>
  
  <p>And in my entity : </p>
  
  <p><strong>1. Project :</strong> </p>
  
  <pre><code>@Transactional
  @Entity
  public class Project implements Serializable{
  
  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  private Long id;
  
  private String name;
  
  private boolean showable = true;
  
  @OneToMany(mappedBy="project", fetch = FetchType.EAGER)
  private Set&lt;Collaborator&gt; collaborators = new HashSet&lt;&gt;();
  
  @Override
  public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result + ((collaborators == null) ? 0 : collaborators.hashCode());
  result = prime * result + ((id == null) ? 0 : id.hashCode());
        }
  //Getters &amp; setters        
  }
  </code></pre>
  
  <p><strong>2. Collaborator :</strong> </p>
  
  <pre><code>@Entity
  public class Collaborator implements Serializable{
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
  
  @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  @JoinColumn(name = "ProjectID" , nullable = true)
  private Project project;
  
  @Override
  public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + ((project == null) ? 0 : project.hashCode());
  return result;
  }
  //Getters &amp; setters      
  }
  </code></pre>
  
  <p>But i'm getting this Error : </p>
  
  <pre><code>HTTP Status 500 - Handler dispatch failed; nested exception is java.lang.StackOverflowError
  
  root cause
  java.lang.StackOverflowError
  java.net.AbstractPlainSocketImpl.available(Unknown Source)
  java.net.SocketInputStream.available(Unknown Source)
  .........
  gestionprojet.java.entities.beans.Project.hashCode(Project.java:179)
  gestionprojet.java.entities.beans.Collaborator.hashCode(Collaborator.java:88)
  </code></pre>
  
  <p>Now when the collaborator table is empty : the request runs perfectly but when I add a collaborator to a project all related requests are broken.</p>
  
  <p><em>P.S :</em> HashCode() &amp; Equals() methods are generated automatically.</p>
  
  <p>Any help would be appreciated. Tank you.</p>