【发布时间】:2018-11-06 22:28:42
【问题描述】:
我们有一个简单的表格:
Human:
+------+
|Height|
+------+
| |
+------+
而且我有一个方法可以增加一个人:
@AutoWired
HumanRepository humanRepo; // JpaRepository
@Transactional(isolationLevel = REPEATABLE_READ)
void addHuman(int height){
if(humanRepo.existsByHeight(height){
throw new HumanWithSuchHeightExists();
}
humanRepo.save(Human.builder().height(height).build())
}
我想保证只存在一个具有特定身高的人。
-
REPEATABLE_READ能保证吗? - 我的代码(伪代码)是否正确满足该条件?
【问题讨论】:
标签: database spring postgresql isolation-level