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

1

I have a @Entity called Employee, when I need to change the properties name, position, salary etc .. I have to do one property at a time as the example below.

My class FunContent

@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 gets the id that came from my FuncionarioController class. The find() method of the repository class as below finds the object and makes the change in the specific property in the charge 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, 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);
    }
    
asked by anonymous 11.05.2017 / 16:52

0 answers