Problem with database concurrency in a cluster

132 Views Asked by At

I have a Spring Boot API with Oracle Database running in a JBoss cluster. I'm trying to use @Lock(LockModeType.OPTIMISTIC_FORCE_INCREMENT) to lock a register at and don't make it to be updatable at the same time for different clients, and that works very well at one instance, but when deploying to the cluster the lock optimistic and pessimist doesn't work at all.

My method

@Lock(LockModeType.OPTIMISTIC_FORCE_INCREMENT)
@Query("SELECT a FROM AvisoPendente a " +
       "WHERE a.id = :avisoId " +
       "AND a.distribuido = FALSE")
Optional<AvisoPendente> findByIdAndIsNotDistribuidoToLock(@Param("avisoId") String avisoId);

My entity

@Entity
@Table(schema = "schema", name = "TAB_AVISO")
public class AvisoPendente {
    @Id
    private String id;

    private String nome;

    @Version
    private Integer version;
}
0

There are 0 best solutions below