title: using @ElementCollection join with non primary key
body: <p>I have two simple tables and an entity:</p>
  <pre><code>CREATE TABLE student(
  id not null auto_increment,
  name varchar(30) not null,
  student_behaviour varchar(30) not null,
  primary key(id)
  );
  
  CREATE TABLE student_uniform(
  id not null auto_increment,
  student_name varchar(30) not null,
  uniform varchar(30) not null,
  primary key(id)
  );
  
  @Entity
  public class Student {
  
      @Id
      @GeneratedValue
      private int id;
  
      private String studentName;
  
      @Enumerated(EnumType.STRING)
      private StudentBehaviour;
  
      @ElementCollection(fetch = FetchType.LAZY)
      @Fetch(FetchMode.SUBSELECT)
      @CollectionTable(name=&quot;student_uniform&quot;,
          joinColumns = @JoinColumn(name=&quot;student_name&quot;)
      @Column(name=&quot;uniform&quot;)
      private Set&lt;String&gt; studentUniforms;
      //getters and setters avoided 
  </code></pre>
  <p>(A student can have more than one uniform)
  I would like to retrieve the student using a JPA repo:</p>
  <pre><code>Student findByName(String name);
  </code></pre>
  <p>The issue I am having is that to extract the list of uniforms, the columns compared are the student.id with student_uniform.student_name which results in an empty list for the studentUniforms attribute.</p>