When you create a datasource in Websphere for a SQL Server database, the default isolation level is Repeatable Read. At first it seems the best choice, but repeatable read as isolation level means the presence of table lock, and with table lock, a deadlock can happen at any time!
For example, considere this application stack:
Java 8
Spring Boot 2.4.1
Websphere 8.5.5
SQL Server 2008
If you need a transaction with REQUIRES_NEW propagation, a deadlock can happen if you are going to update the same tables in the parent and child transaction. This because the isolation level is Repeatable Read.
The solution is to relax the isolation level to Read Committed. You avoid deadlock and with hibernate optimistic lock, there is no possibility to miss information.
To set the isolation level of a datasource in Websphere, you have to navigate the path:
Data sources > [datasource name] > Custom properties
and set
webSphereDefaultIsolationLevel=2
where 2 means Read Committed.
That’s what you need to avoid deadlock!
And remember, if you need a pessimistic lock, with JPA is simple to set table lock for a single query (see for example my previous post about it).