symfony - Symfony Doctrine 事务循环问题
问题描述
我正在尝试根据用户详细信息创建用户并阻止他们的考试编号以下是我的代码,
我正在使用事务来查看考场是否可用,如果不可用则恢复创建用户,
但是回滚也恢复了我维护的日志表以存储分配中的问题。
foreach($user_details as $ky=> $user) {
$this->em->getConnection()->beginTransaction();
try {
$this->em->persist($user);
$this->em->flush();
// this function checks if user details contains some condition
// for allocation of exam hall,
// like fees paid etc
$examHallAvailable = $this->checkHallavailable($user);
if($examHallAvailable) {
// updated exam details for user
$user->addExamHall($examHallAvailable);
$this->em->persist($user);
$this->em->flush();
$this->em->getConnection()->commit();
} else {
// i want to rollback creation of this user
// but continue other user creation
$this->em->getConnection()->rollBack();
}
// this adds a log of user add fail in another table
$this->updateLog($user);
}catch(Exception $ex) {
$this->em->getConnection()->rollBack();
}
如果我在没有考场标志的情况下删除回滚,则会出现以下错误
The optimistic lock on an entity failed.
我如何继续 for 循环而忽略用户的错误,并在出现错误时防止日志表更新回滚?
解决方案
推荐阅读
- python - python中的uart通信读取错误
- flutter - 如何在 Flutter 中为不同的小部件使用相同的 BLoC?
- git - 我不明白使用 git diff 的文件中的差异
- sql - 在 TSQL、Azure 数据库中捕获服务主体的名称而不是它的 ID
- python - Python如何在文件中搜索特定字符串
- android - Cordova 在为 ionic android 添加平台时遇到错误
- python - 拆分和重组 TensorFlow 数据集
- github-api - 列出给定 PAT 的 GitHub 赞助商订阅
- javascript - HTML Canvas - 形状之间的颜色过渡(形状不重叠)
- java - 如何使用 Akka 建模聚合关系