title: JPQL for One to Many Relationship
body: <p>I'm trying to create a JPQL for one to many relationship, namely user and device as 1 user can have one to many devices. I want to find the whole object of the device if it is owned by the user and the device name is correct.</p>
  
  <p>If it is a SQL query then I can just do the query only for the device as follow:</p>
  
  <pre><code>select * from DEVICE where USER_ID = 2 and DEVICENAME = "mypc";
  </code></pre>
  
  <p>where USER_ID is the foreign key in DEVICE table. But how can I do the JPQL query for the user and device table? Here are some info for User and Device class</p>
  
  <pre><code>@Entity
  public class User {
  @Id
  @GeneratedValue(strategy = GenerationType.TABLE)
  public int id;
  public String username;
  public String firstname;
  public String lastname;
  public String hashPassword;
  
  @OneToMany(mappedBy = "user")
  public List&lt;Device&gt; devices = new ArrayList&lt;Device&gt;();
  
  
  }
  
  @Entity
  public class Device {
  
      @Id
      @GeneratedValue(strategy = GenerationType.TABLE)
      public int id;
      public String deviceName;
      @ManyToOne
      public User user;
      String deviceOS;
      String deviceType;
      String attributes;
      boolean standard;
  }
  </code></pre>