代码之家  ›  专栏  ›  技术社区  ›  dMedia

Symfony删除实体从不刷新

  •  1
  • dMedia  · 技术社区  · 9 年前

        $form = $this->createForm('AppBundle\Form\UserType', $user);
        $form->handleRequest($request);
    
        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $user->setRoles($this->setUserRoles($user));
    
            $changed = $this->checkChanged($em->getUnitOfWork()->getOriginalEntityData($user), $request->request->get('app_user_profile'));
            if ($changed) {
    //            $sql = "DELETE FROM sessions WHERE sess_id = '".$user->getSessId()."'";
    //            $em->getConnection()->exec($sql);
    //            $em->getConnection()->commit();
    
                $entity = $em->getRepository('AppBundle:Sessions')->find($user->getSessId());
                if ($entity) {
                    $em->remove($entity);
    //                $em->flush($entity);
                }
                $user->setSessId(null);
            }
            $em->persist($user);
            $em->flush();
            return $this->redirectToRoute('users_list');
        }
    

    SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction

    我用同样的结果注释了我尝试过的代码。MySql日志文件显示删除命令后暂停10秒,我不知道它在等待什么,甚至不知道为什么 $em->getConnection()->commit();

    2017-08-09T10:02:36.334195Z   217 Connect   user@localhost on mydb using TCP/IP
    2017-08-09T10:02:36.336556Z   217 Query SELECT t0.username AS username_1, <...> FROM fos_user t0 WHERE t0.id = 1 LIMIT 1
    2017-08-09T10:02:36.373640Z   217 Query DELETE FROM sessions WHERE sess_id = '1gjo6har0vttn7ru63pjrptti4'
    2017-08-09T10:03:27.489764Z   216 Query INSERT INTO sessions (sess_id, sess_data <...>
    
    2 回复  |  直到 9 年前
        1
  •  0
  •   Mcsky    9 年前
    • 您的表中有多少个会话行?
    • 你有你的课程索引吗。sess\u id列?
    • 您是否尝试使用mysql CLI或phpmyadmin运行此查询?
    • 大约有多少?

    请删除会话和用户实体代码以检查关系

    PS:很抱歉,由于我的声誉,我无法发表评论(<50)

        2
  •  0
  •   dMedia    9 年前

    if ($user->getId() == $this->getUser()->getId()) {
        return $this->redirectToRoute('fos_user_security_logout');
    }