Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

233
Visualizações
@Transactional multiple update; commit every single query

I have 2 methods in my service

public void updateAll() {
   long[] ids = new long[] {1,2,3,4,5,6,7,8,9,10};
   for (long id : ids) {
        updateId(id);
    }
}

public updateId(long id) {
  repository.update(id);
}

Let's assume that after the 5th update I have an exception, I would like that the first 4 operations would be committed anyway.

I'm using the @Transactional annotation but if I put the annotation in both methods it doesn't work.

Do I need other parameter?? It might be propagation??

Could you show me how to set this methods?

Thank you!!

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You need a separate @Transactional on updateId with REQUIRES_NEW.

about 4 years ago · Santiago Trujillo Relatório

0

Just have:

@Transactional(propagation = Propagation.REQUIRES_NEW)
public updateId(long id) {
}

But, the important bit, call that method from another class. i.e. move your loop out of this class.

The transactional annotations only kick-in when that public method is called from the outside. Within the same class, calling one transactional method from another will still only use the transaction of the first method.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda