title: How to create a TypedQuery in JPQL that queries two tables using an implicit join?
body: <p>I'm trying to learn how to use implicit joins in JPQL. An example I'm working from seems to suggest that one can reference a foreign key as a path and then have access to attributes in the table the foreign key references.</p>
  
  <p>It's a 1:M mandatory relationship between User and Report.
  userId is the foreign key that references User.</p>
  
  <p>I've checked that I have the right libraries imported that I have the right mapping (@JoinColumn, @ManyToOne, @OneToMany, mappedBy, etc), everything seems to be okay.</p>
  
  <pre><code>@GET
  @Path("findByTotalCalBurnedAndHeight/{height}/{totalCalBurned}")
  @Produces({"application/json"})
  public List&lt;Report&gt; findByTotalCalBurnedAndHeight(@PathParam("height") Integer height, @PathParam("totalCalBurned") Integer totalCalBurned) {
      TypedQuery&lt;Report&gt; q = em.createQuery("SELECT r FROM Report r WHERE r.totalCalBurned = :totalCalBurned AND r.userId.height = :height", Report.class);
      q.setParameter("height", height);
      q.setParameter("totalCalBurned", totalCalBurned);
      return q.getResultList();
  }
  </code></pre>
  
  <p>As seen above I'm trying to access the "height" attribute in the "User" table with: r.UserId.height</p>
  
  <p>Based on the example I'm working from I'd expect the join to work here however the result I'm getting is this error: "The state field path 'r.userId.height' cannot be resolved to a valid type."</p>
  
  <p>Am I missing something here? Any feedback is much appreciated.</p>
  
  <p>Update to show mapping:</p>
  
  <p>In report class:</p>
  
  <pre><code>@Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Basic(optional = false)
  @Column(name = "REPORT_ID")
  private Integer reportId;
  
  @JoinColumn(name = "USER_ID", referencedColumnName = "USER_ID")
  @ManyToOne(optional = false)
  @Basic(optional = false)
  @NotNull
  @Column(name = "USER_ID")
  private Integer userId;
  </code></pre>
  
  <p>In user class:</p>
  
  <pre><code>@Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Basic(optional = false)
  @Column(name = "USER_ID")
  private Integer userId;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "userId")
  
  @Basic(optional = false)
  @NotNull
  @Column(name = "HEIGHT")
  private int height;
  </code></pre>