how to change an object instead of one properties at a time using JPA

Asked

Viewed 49 times

1

I have a @Entity Call employee, when I need to change properties name, position, salary etc.. I have to make one property at a time as example below.

My class Functioncontroller

@Transactional
public void atualizar(FuncionarioModel funcionarioModel) throws NegocioException {
    if (funcionarioModel.getCargo().isEmpty()) {
        throw new NegocioException("Não é possível fazer a Alteração campo cargo está vazio !");
    }
    this.funcionarioRepository.porId(funcionarioModel.getCodigo()).setCargo(funcionarioModel.getCargo());
}

My repository class receives the id who came from my class FuncionarioController. The method find() of the repository class as below finds the object and makes the change in the property specifies in the position case.

public FuncionarioModel porId(Long id) {
    return manager.find(FuncionarioModel.class, id);
}

I wonder if it is possible instead of changing one property at a time, to make the change in the object, thus avoiding a large code. As I’m doing today, I have to write all the properties again.

Não Recebi nenhum retorno mais a resposta era simples, resolvi conforme abaixo.

**classe repositório**
public void alterar(FuncionarioModel funcionario) {
         this.manager.merge(funcionario);
    }

**classe Controle**
@Transactional
    public void atualizar(FuncionarioModel funcionarioModel) throws NegocioException {
        if (funcionarioModel.getCargo().isEmpty()) {
            throw new NegocioException("Não é possível fazer a Alteração campo cargo está vazio !");
        }
        this.funcionarioRepository.alterar(funcionarioModel);
    }
  • What would change the whole object? What do you need to change in it ?

  • Douglas Thanks for the return, I think I managed to resolve as posted above, but I will reset the question , who knows you do not have a better solution.... Well I have an object called Employee and I need to make changes in the following properties name, cago, salary and I would like to do this at once only by setting the object ie Employee instead of setting one property at a time...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.