title: How to read data from database with JPA/JPQL Query and Foreign Keys
body: <p>I am new to JPA and i have a problem with it. Suppose that we have two tables which are related by a ManytoOne association.
  table 1: person (idp,name,#idep)
  table 2: departement (idep,deptname)</p>
  
  <p>I want to write a jpa query like this query in sql :</p>
  
  <pre><code>select person.name,departement.deptname from person,departement where person.idep=department.idep
  </code></pre>
  
  <p>Person.java</p>
  
  <pre><code>@Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  private Integer idp;
  private String name;
  
  //Jointures JPA
  @ManyToOne(fetch=FetchType.LAZY)
  @JoinColumn(name="id_dep")
  private Departement dept;
  
  //Getters/Setters
  </code></pre>
  
  <p>Departement.java</p>
  
  <pre><code>@Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Integer id_dep;
  private String deptname;
  
  @OneToMany(mappedBy="departement", cascade = { CascadeType.ALL })
  private List&lt;Person&gt; listperson=new ArrayList&lt;Person&gt;();
  
  //getters/setters
  </code></pre>
  
  <p>I tried this attempt but it didn't work:</p>
  
  <pre><code>entityManager.createQuery("select p.name,d.deptname " + " from Person a,Department d " + "where a.id_dep =d.id_dep ").getResultList();
  </code></pre>