JPA JPQL Lock not working

155 views Asked by At

First selects all rows with pessimistic lock then updates every row. Second one does the same thing. I thought second attempt should fail, but it's just working fine. How can I make second attempt fail?

List<Developer> devs = em
        .createQuery("select c from Developer c ", Developer.class)
        .setLockMode(LockModeType.PESSIMISTIC_WRITE).getResultList();

for (Developer developer : devs) {
    developer.setName("asdf");
}

List<Developer> devs2 = em
        .createQuery("select c from Developer c ", Developer.class)
        .setLockMode(LockModeType.PESSIMISTIC_WRITE).getResultList();

for (Developer developer : devs2) {
    developer.setName("1234");
}
0

There are 0 answers