Spring-webmvc 4.1.6 / Spring-data-jpa 1.7.2 / Oracle 12c
I have my app running on localhost with debug mode in Netbeans. I use the jetty-maven-plugin as a server and try to test a service method annotated with @Transactional.
Service Method.
@Transactional("primaryTransactionManager")
@Override
public JsonResponseEntity<Dinero> Cancel_Deposit(Dinero dinero, EnumComportamientosDIN comportamiento_key, Boolean fromserver) {
dateUtils = new DateRangeUtils();
List<Dinerod> detalles = dinero.getDinerods();
for (Dinerod detalle : detalles) {
Dinero origen_depo = dineroRepository.findOneByAplica(detalle.getAplica(), detalle.getAplicaid());
BigDecimal saldo_actual = origen_depo.getSaldo();
BigDecimal importe_debitado = detalle.getImporte();
saldo_actual = saldo_actual.add(importe_debitado);
origen_depo.setSaldo(saldo_actual);
dineroRepository.save(origen_depo);
}
}
JPA Repository
@Lock(LockModeType.PESSIMISTIC_WRITE)
@QueryHints({@QueryHint(name = "javax.persistence.lock.timeout", value = "30000")})
@Query("SELECT x FROM Dinero x WHERE x.mov = :aplica AND x.movid = :aplicaid")
Dinero findOneByAplica(@Param("aplica") String aplica, @Param("aplicaid") String aplicaid);
I don't know if my test method is wrong but it is the following: since application is running on localhost; From another computer on the same network, I simulate that it is another person using the same application. So I run the same method with two different computers at the same time, trying to simulate a transaction crash. the same one I try to solve with PESSIMISTIC_WRITE.
But when I run the web form from two different computers at the same time, the exclusive locking of the record in the database is not done.

