title: How to write a Spring Data JPA Specification with multiple joins?
body: <p>The project I'm working on was generated with JHipster with support for entity filtering, which uses Spring Data JPA Specifications under the hood.</p>
  
  <p>The model is as follows (in JDL):</p>
  
  <pre><code>entity Student {
      name String
  }
  
  entity Course {
      name String
  }
  
  entity Enrollment {
  }
  
  entity Attendance {
      date LocalDate
  }
  
  relationship OneToMany {
      Student to Enrollment(student required),
      Course to Enrollment(course required),
      Enrollment to Attendance(enrollment required)
  }
  
  filter all
  service all with serviceClass
  </code></pre>
  
  <p>JHipster generates boilerplate for filtering <code>Attendance</code> by <code>enrollmentId</code>, but I'd like to extend it to be able to filter by <code>studentId</code> and <code>courseId</code> as well.</p>
  
  <p>So, how can I implement a Specification that would perform a query like:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT
    attendance.date, student.name as student, course.name as course
  FROM attendance
  JOIN enrollment
    ON enrollment.id = attendance.enrollment_id
  JOIN student
    ON student.id = enrollment.student_id
    AND studend.id = 1
  JOIN course
    ON course.id = enrollment.course_id
    AND course.id = 2;
  </code></pre>