【发布时间】:2018-02-15 13:56:49
【问题描述】:
我使用休眠作为 JPA 提供程序
@RestController
public class RestController {
private final TestService testService;
@PostMapping(value = "/file/{entityId}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public void test(@PathVariable @NotNull UUID entityId) {
testService.delete(entityId);
}
}
class TestService {
@AutoWired
EntityRepository repo; // <- Crud repository from Spring Data
public void delete(UUID id2){
//if row not exists with id == id2
throw NoFoundException
// else
//remove from database using repo.
}
}
以及如何解决以下情况:
- “如果行不存在且 id == id2”评估为 false,因为对象实际上存在。
- 其他线程删除了该行。
- "remove from database using repo"
【问题讨论】:
标签: spring hibernate spring-boot spring-data