I am making an employee registration, and in that register already have departments registered in the bank. So, at that moment I run the bank to present the data in the view, but when I finish the registration, this previously selected "department", instead of just registering it as the department id, it is creating a new department and saved in the employee table the new id. Method to recover departments:
public List getProjetos() {
ProjetoDAO projetoDAO = new ProjetoDAO();
List<Projeto> listaProjeto = projetoDAO.listarProjeto();
return listaProjeto;
}
Another problem I'm having is that I'm doing the lazy at the moment it calls the get of the "department", I know the problem is here, because whenever it gives the get, it will create a new one.
public Projeto getProjeto() {
if (projeto == null) {
projeto = new Projeto();
}
return projeto;
}
}
Employee Class
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "tbl_funcionario_has_tbl_projeto", joinColumns = {
@JoinColumn(name = "tbl_funcionario_fun_codigo") }, inverseJoinColumns = {
@JoinColumn(name = "tbl_projeto_pro_codigo") })
private List<Projeto> projeto;
Doubt is how to make it check that this department already exists and not create a new one?