Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
@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 Respuestas
Responde la pregunta

0

You need a separate @Transactional on updateId with REQUIRES_NEW.

about 4 years ago · Santiago Trujillo Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda