2

Is it possible to get a DB deadlock exception with Spring + JPA Repositories + H2/PostgreSQL?

I've found several examples of how to simulate a deadlock with raw SQL (one, two, three, four), but my goal is to do the same in a more high-level environment.

I did some experiments with concurerent threads, CrudRepository.save(entity), and Thread.sleep() but to no avail (I guess it's not possible). What else can I try?

  • 1
    Sure, entityManager has a lock method, you should be able to do pessimistic locking and cause a deadlock. – Nathan Hughes Apr 01 '19 at 22:47
  • Well, I achieved some results with 2 instances of entityManager (and no Threads at all). But before I share the code, I'd like to make sure whether I actually run into deadlock.. So, now my application freezes after commiting the last SQL query, and it actually looks like the deadlock, but I don't see any exceptions/error messages like "deadlock detected" in console. It is okay? I tried both with H2 and PostgreSQL. – Alexander Ishmuradov Apr 02 '19 at 21:59

0 Answers0