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

204
Vistas
Explaning Optimistic Locking Failed Exception after PSQL exception

I have a fallowing scenario that I want to understand clearly so I can fix it in a proper way.

Some entity have to be persisted to PostgreSQL database using hibernate. This is the course of events that happens before the errors.

  1. Entity attempts to be saved into database (as a part of the logic with a multi-threaded execution). That entity has a null character (0x00) as a part of it's attribute and I get an exception caused by

    org.postgresql.util.PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0x00
    

    because PostgreSQL cannot persist null chars, which is OK.

  2. That same entity is then modified, but now in a single-threaded environment after the end of a parallel execution of the above mentioned logic and is persisted again to update the database.

    Now I get an Optimistic Locking Failed exception saying that entity has already been saved and that the object is "Stale".

    org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [com.yc.isystem.business.Offer] with identifier [691909329]:
         optimistic locking failed; nested exception is
         org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.yc.isystem.business.Offer#691909329]
    

Can someone explain what happens in the background and how can I prevent this from happening?

over 4 years ago · Santiago Trujillo
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