title: Hibernate @ManyToOne with join table with extra column seems generate infinite loop
body: <p>I have 3 entities : Contract, Person and ContractPerson. ContractPerson is a join table between Contract and Person with extra fields so I created a separate entity.</p>
  
  <p>Contract.java:</p>
  
  <pre><code>   import lombok.Data;
     import javax.persistence.*;
     import java.util.HashSet;
     import java.util.Set;
  
     @Data
     @Entity
     @Table (name = "contract")
     public class Contract {
  
         @Id
         @GeneratedValue
         @Column (name = "contract_id")
         private Long id;
  
         @Column (name = "contract_ref")
         private String ref;
  
         @OneToMany (mappedBy = "contract", fetch = FetchType.LAZY)
         private Set&lt;ContractPerson&gt; contractPersons = new HashSet&lt;&gt;();
      }
  </code></pre>
  
  <p>Person.java:</p>
  
  <pre><code>   import lombok.Data;
     import javax.persistence.*;
  
     @Data
     @Entity
     @Table (name = "person")
     public class Person {
  
         @Id
         @GeneratedValue
         @Column (name = "person_id")
         private Long id;
  
         @Column (name = "formality")
         private String formality;
  
         @Column (name = "first_name")
         private String firstName;
  
         @Column (name = "last_name")
         private String lastName;
  
         @OneToMany (mappedBy = "person", fetch = FetchType.LAZY)
         private Set&lt;ContractPerson&gt; contractPersons = new HashSet&lt;&gt;();
      }
  </code></pre>
  
  <p>ContractPerson.java:</p>
  
  <pre><code>import lombok.Data;
  
  import javax.persistence.*;
  
  @Data
  @Entity
  @Table (name = "contract_person")
  public class ContractPerson {
  
      @Id
      @GeneratedValue
      @Column (name = "contract_person_id")
      private Long id;
  
      @Column (name = "description")
      private String description;
  
      @ManyToOne
      @JoinColumn (name = "id_of_person")
      private Person person;
  
      @ManyToOne
      @JoinColumn (name = "id_of_contract")
      private Contract contract;
  }
  </code></pre>
  
  <p>When I try with Spring Data JPA to get a contract with a particular id it generates this kind of input:</p>
  
  <pre><code>2014-12-29 18:02:10.843 DEBUG 1932 --- [qtp745716999-20] e.p.i.CollectionReferenceInitializerImpl : Found row of collection: [xxx.Contract.contractPersons#199]
  2014-12-29 18:02:10.843 DEBUG 1932 --- [qtp745716999-20] o.h.e.l.internal.CollectionLoadContext   : 1 collections were found in result set for role: xxx.Contract.contractPersons
  2014-12-29 18:02:10.843 DEBUG 1932 --- [qtp745716999-20] stractLoadPlanBasedCollectionInitializer : Loading collection: [xxx.Contract.contractPersons#199]
  2014-12-29 18:02:10.879 DEBUG 1932 --- [qtp745716999-20] o.h.l.p.e.p.i.ResultSetProcessorImpl     : Preparing collection intializer : [xxx.Contract.contractPersons#199]
  2014-12-29 18:02:10.879 DEBUG 1932 --- [qtp745716999-20] o.h.l.p.e.p.i.ResultSetProcessorImpl     : Starting ResultSet row #0
  2014-12-29 18:02:10.879 DEBUG 1932 --- [qtp745716999-20] e.p.i.CollectionReferenceInitializerImpl : Found row of collection: [xxx.Contract.contractPersons#199]
  2014-12-29 18:02:10.880 DEBUG 1932 --- [qtp745716999-20] o.h.l.p.e.p.i.ResultSetProcessorImpl     : Starting ResultSet row #1
  2014-12-29 18:02:10.880 DEBUG 1932 --- [qtp745716999-20] e.p.i.CollectionReferenceInitializerImpl : Found row of collection: [xxx.Contract.contractPersons#199]
  2014-12-29 18:02:10.880 DEBUG 1932 --- [qtp745716999-20] o.h.e.l.internal.CollectionLoadContext   : 1 collections were found in result set for role: xxx.Contract.contractPersons
  etc...
  </code></pre>
  
  <p>After an impressive amount of repetition of this log I have this:</p>
  
  <pre><code>2014-12-29 18:25:41.805  WARN 1992 --- [tp2080715589-19] o.h.e.loading.internal.LoadContexts      : HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@53504a5c&lt;rs=com.mysql.jdbc.JDBC4ResultSet@448cef4b&gt;
  2014-12-29 18:25:41.805  WARN 1992 --- [tp2080715589-19] o.h.e.loading.internal.LoadContexts      : HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@3c4208bf&lt;rs=com.mysql.jdbc.JDBC4ResultSet@55932a51&gt;
  2014-12-29 18:25:41.805  WARN 1992 --- [tp2080715589-19] o.h.e.loading.internal.LoadContexts      : HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@134c5281&lt;rs=com.mysql.jdbc.JDBC4ResultSet@44927753&gt;
  2014-12-29 18:25:41.805  WARN 1992 --- [tp2080715589-19] o.h.e.loading.internal.LoadContexts      : HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@77bc9d0c&lt;rs=com.mysql.jdbc.JDBC4ResultSet@6520ed53&gt;
  2014-12-29 18:25:41.805  WARN 1992 --- [tp2080715589-19] o.h.e.loading.internal.LoadContexts      : HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@7feabc3d&lt;rs=com.mysql.jdbc.JDBC4ResultSet@6a97c953&gt;
  2014-12-29 18:25:41.805  WARN 1992 --- [tp2080715589-19] o.h.e.loading.internal.LoadContexts      : HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@bec8a67&lt;rs=com.mysql.jdbc.JDBC4ResultSet@4e0d0b57&gt;
  2014-12-29 18:25:41.805  WARN 1992 --- [tp2080715589-19] o.h.e.loading.internal.LoadContexts      : HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@5672764e&lt;rs=com.mysql.jdbc.JDBC4ResultSet@1d0c0d57&gt;
  2014-12-29 18:25:41.806  WARN 1992 --- [tp2080715589-19] o.h.e.loading.internal.LoadContexts      : HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@74b52738&lt;rs=com.mysql.jdbc.JDBC4ResultSet@5ee5b357&gt;
  </code></pre>
  
  <p>If I remove the link in Contract there is no error.</p>
  
  <p>Do you have any idea ? Infinite loop ? Other ? </p>
  
  <p>Thanks in advance for your help.</p>