1

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;
}
Tim Moore
  • 8,958
  • 2
  • 23
  • 34
rafu
  • 35
  • 1
  • 3
  • When you say "doesn't work at all" what do you mean? What do you expect and what do you get? – Roman-Stop RU aggression in UA Aug 19 '21 at 11:55
  • I expect the register will be locked and doesn't be acessed by any client, but it is – rafu Aug 19 '21 at 15:06
  • You need to show what exactly clients are doing as in what operation they are doing. For example optimistic locking will not prevent multiple client from executing this `findByIdAndIsNotDistribuidoToLock` method simultaneously. And from your question it is not clear what you are doing. Use `Edit` link under the question to the steps your code is executing. And how exactly in these steps you expect that record is locked. – Roman-Stop RU aggression in UA Aug 19 '21 at 16:51
  • the clients are trying to access the ```AvisoPendente``` with id "1" at the same time, but just the first one is to be able to access the register. So, when I'm doing the tests at the loval machine, they work good, but when I deploye to my cluster, the 2 clients are able to access and update the register at the same time. – rafu Aug 23 '21 at 20:30

0 Answers0