I have insert
where I save a record, and I need to use the result of the value saved in another insert
.
Empresa emp = new Empresa();
emp.setId(1);
emp.setNome("Nome da empresa");
repository1.saveAndFlush(emp);
RelacaoEmp relEmp = new RelacaoEmp();
relEmp.setId(100);
relEmp.setIdEmp(1); //O mesmo Id Cadastrado na empresa
relEmp.setTpEmp(10);
repository2.save(relEmp);
When this operation is effective, it says that company 1 does not exist.
Is there any way I can enforce registration of repository1
before running repository2
to not give this problem?