0
I’m making an employee register, and this register already has departments registered in the bank. So, at this point I walk through the database to present the data in the view, but when I finish the registration, this "department" selected earlier, instead of just registering it as the department id, it is creating a new department and saves 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 Lazy the moment I call the "department" get, I know the problem is here, because whenever he gives the get, will create a new.
public Projeto getProjeto() {
if (projeto == null) {
projeto = new Projeto();
}
return projeto;
}
}
Working 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;
The doubt is how to make him verify that already exists that department and not create a new?
Have you noted the relationship in the entities? Post the entities. The table in the bank is a single (employee department) or separate?
– Marcelo
She’s separated... I posted the relationship there...
– Marquin Ferreira
Your doubt is based on creating a new method or you suspect that your notes are wrong?
– Roknauta
My question is how to do when calling the get of the Project, it does not create another project but recover the id and save in the employee table.
– Marquin Ferreira