3
I have the following query in the postgres database:
select * from trabalha_projeto tp inner join Empregado e on
e.matricula = tp.empregado
how it turns it into a JPQL query?
I’m having a hard time returning the values:
- First : for not knowing how to formulate the query with jpql
- Second: Due to the fact of having two entities java, and to relate them have three tables in the database
My two entities Employee and Project saw the tables:
Project
Employee
Empregado_Projeto(empregado_matricula,projetos_codigo)
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?
Thanks for the force, I edited the question to better clarify my doubt.
– Pena Pintada