title: JPA: Foreign Key as parameter in NamedQuery
body: <p>I'm trying to return <code>Raadpleging</code> objects from my DB. Those objects contain a <code>Persoon</code> and a <code>Les</code>. My goal is to return all Raadplegingen where the ID of the Les equals the parameter.</p>
  
  <p>I'm not sure how to do this in my query. I'm also not so sure if my first namedQuery will also return the Persoon and Les property, or if I need a join for that.</p>
  
  <p>As you can see below, I tried using the parameter like this <code>WHERE r.les  = :lesId</code>, which isn't correct I think.</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Access(AccessType.PROPERTY)
  @Table(name = "Raadplegingen")
  @NamedQueries({
      @NamedQuery(name = "ClubRaadpleging.getAlleRaadplegingen",
              query = "SELECT r FROM ClubRaadpleging r"),
      @NamedQuery(name = "ClubRaadpleging.findByLes",
              query = "SELECT r FROM ClubRaadpleging r JOIN ClubLes l ON l.id =r.les.id WHERE r.les  = :lesId")
  })
  public class ClubRaadpleging implements Serializable {
  
      private int id;
      private ClubLes les;
      private ClubPersoon persoon;
      private Date datum;
  
      public ClubRaadpleging() {
      }
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "RaadplegingId")
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      @ManyToOne(cascade = CascadeType.PERSIST)
      @JoinColumn(name = "LesId")
      public ClubLes getLes() {
          return les;
      }
  
      public void setLes(ClubLes les) {
          this.les = les;
      }
  
      @ManyToOne(cascade = CascadeType.PERSIST)
      @JoinColumn(name = "PersoonId")
      public ClubPersoon getPersoon() {
          return persoon;
      }
  
      public void setPersoon(ClubPersoon persoon) {
          this.persoon = persoon;
      }
  
      @Temporal(TemporalType.DATE)
      public Date getDatum() {
          return datum;
      }
  
      public void setDatum(Date datum) {
          this.datum = datum;
      }
  
  }
  
  
  </code></pre>