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

203
Visualizações
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 à 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