I have the following query in the postgres database:
select * from trabalha_projeto tp inner join Empregado e on
e.matricula = tp.empregado
How does it transform it into a JPQL query? I'm having a hard time returning values:
- First: not knowing how to formulate the query with jpql
- Second: Due to having two entities java, and to relate them have three tables in the bank
My two entities Employee and Project saw the tables:
Project
Employee
Employee_Project (employee_matricula, code_projects)
Here are my java classes:
Employee Class
@Entity
@SequenceGenerator(name = "empregado_sequence", sequenceName = "empregado_sequence",
allocationSize = 1, initialValue = 1)
public class Empregado implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "empregado_sequence")
private int matricula;
private String nome;
private Double salario;
@OneToMany(cascade = CascadeType.ALL, targetEntity = Projeto.class ,fetch = FetchType.EAGER)
private List<Projeto> projetos;
public Empregado() {
}
Project Class
@Entity
@SequenceGenerator(name = "projeto_sequence" , sequenceName = "projeto_sequence",
allocationSize = 1 , initialValue = 1)
public class Projeto implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE , generator = "projeto_sequence")
private int codigo;
private String nome;
public Projeto() {
}
How to return all employees working on a project using a join?