posted 2 years ago
Well, in point of fact, I've never seen a complete list of the things that enforce transactions. Some are part of Spring, some are part of the database itself and some occur at differing levels and then you can also define your own tangled web of transaction types.
However, at its basic level, when two transactions commit with conflicts, the conflict is caught by comparing the entities field-by-field for equality (the "equals()" method is not good enough here, as it has a special meaning in JPA). If the fields don't match, that causes a ConcurrentModificationException to be thrown and the transaction fails and is rolled back. If your paranoia level is sufficiently high (and as I recall, it is by default), JPA will actually read the current record from the database and compare, not just look at local changes.
This probably won't detect concurrency violations on a single Entity instance (that is, where Entity instance A and Entity instance B are not only "equals()", but "=="), because that's an actual synchronization error, but if there are multiple transactions running against copies of the same("equals()") Entity that are not "==", that's how trouble is prevented.
I'm going to be a "small government" candidate. I'll be the government. Just me. No one else.