有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java什么是JPA悲观显式@Lock用例(而仅仅@Transactional不是选项)?

我对JPA和DB锁(乐观型和悲观型)和事务、它们的工作原理和保证有一定的了解

A TransactionRequiredException is thrown if there is no active transaction when lock is called because explicit locking requires an active transaction.

所以我的问题是:当事务(JPA案例中的@Transactional)不够用,需要显式使用@Lock(LockModeType.epositic_*)时,用例是什么

我对精确的悲观锁感兴趣,并期望有如下用例:

Alice and Bob simultaneously edit page on wikipedia, Alice start to edit a page and locked it..........................and transaction is redundant/not enough/low performance in this case ............................

我不期望:

  1. Use @Lock when you need just a lock

  2. Use optimistic lock its better

  3. Locking is used to prevent dirty reads (reading data that hasn't been committed) and non-repeatable reads (reading data that gets deleted by another transaction before the one reading is finished).


共 (0) 个答案