title: JPQL Query error with Spring JPA and Hibernate
body: <p>I am trying to fetch all the Skills relating to a specific Person.</p>
  
  <p>Getting the following error when trying to fetch data from MySQL DB using JPQL in my Spring Boot application:</p>
  
  <blockquote>
    <p>org.hibernate.QueryException: could not resolve property: person_skill of: com.skilltrack.app.Domain.Skill [SELECT s FROM com.skilltrack.app.Domain.Skill s JOIN s.person_skill ps WHERE ps.fk_person = ?1 ]</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <p>Person.java</p>
  
  <pre><code>@Data
  @EqualsAndHashCode(exclude = "personCourses")
  @Entity(name = "person")
  @Table(name = "person")
  public class Person implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Integer person_id;
  
      @NotBlank
      private String name;
  
      @NotBlank
      private String surname;
  
      @NotBlank
      private String email;
  
      @NotBlank
      private String password;
  
      @NotBlank
      private String personType; //admin or user
  
      @JsonIgnore
      @ManyToMany  // this mapping is referred to in the Course class
      @JoinTable(name = "person_course",
              joinColumns = @JoinColumn(name = "fk_person", referencedColumnName = "person_id"),
              inverseJoinColumns = @JoinColumn(name = "fk_course", referencedColumnName = "course_id"))
      private List&lt;Course&gt; personCourses;
  
      @JsonIgnore
      @ManyToMany  // this mapping is referred to in the Skill class
      @JoinTable(name = "person_skill",
              joinColumns = @JoinColumn(name = "fk_person", referencedColumnName = "person_id"),
              inverseJoinColumns = @JoinColumn(name = "fk_skill", referencedColumnName = "skill_id"))
      private List&lt;Skill&gt; personSkills;
  </code></pre>
  
  <p>Course.java</p>
  
  <pre><code>@Data
  @EqualsAndHashCode(exclude = "skills")
  @Entity(name = "course")
  @Table(name = "course")
  public class Course {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Integer course_id;
  
      @NotBlank
      private String name;
  
      @NotBlank
      private String description;
  
      @JsonIgnore
      @ManyToMany(mappedBy = "courses") // mapping defined in Skill already
      private List&lt;Skill&gt; skills;
  
      @NotBlank
      private Boolean completed; // 0 no 1 yes
  
      @JsonIgnore
      @ManyToMany(mappedBy = "personCourses")
      private List&lt;Person&gt; coursePerson;
  </code></pre>
  
  <p>Skill.java</p>
  
  <pre><code>@Data
  @EqualsAndHashCode(exclude = "courses")
  @Entity(name = "skill")
  @Table(name = "skill")
  public class Skill {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Integer skill_id;
  
      @NotBlank
      private String name;
  
      @NotBlank
      private String description;
  
      @JsonIgnore
      @ManyToMany(cascade = CascadeType.ALL)  // this mapping is referred to in the Course class
      @JoinTable(name = "course_skills",
              joinColumns = @JoinColumn(name = "fk_skill", referencedColumnName = "skill_id"),
              inverseJoinColumns = @JoinColumn(name = "fk_course", referencedColumnName = "course_id"))
      private List&lt;Course&gt; courses;
  
      @JsonIgnore
      @ManyToMany(mappedBy = "personSkills")
      private List&lt;Person&gt; skill_person;
  </code></pre>
  
  <p>PersonRepository.java</p>
  
  <pre><code>@Repository
  public interface PersonRepository extends JpaRepository&lt;Person, Integer&gt; {
  
      @Query(value =
              "SELECT s " +
              "FROM skill s JOIN s.person_skill ps " +
              "WHERE ps.fk_person = ?1 ")
      List&lt;Skill&gt; getPersonSkills(Integer personID);
  }
  
  
  The issue is with the JPQL statement:
  "SELECT s FROM skill s JOIN s.person_skill ps WHERE ps.fk_person = ?1 "
  
  I have tried the following variations:
  
  "SELECT s FROM skill s INNER JOIN s.person_skill ps WHERE ps.fk_person = ?1"
  
  "SELECT s FROM skill s JOIN FETCH s.person p WHERE ps.fk_person = ?1"
  
  "SELECT s FROM skill s JOIN s.person p JOIN s.person_skill ps WHERE ps.fk_person = ?1"
  
  "SELECT s FROM skill s JOIN person p JOIN person_skill ps WHERE ps.fk_person = ?1"
  </code></pre>
  
  <p>How should I change my JPQL query to return a list of Skills relating to a specific Person?</p>