Unfortunately, we have not another solution except one: change session isolation level. Mostly we don't need to change isolation level. Though sometimes should do that.
/** @var \Doctrine\ORM\EntityManager $entityManager */
$oldIsolationLevel = $entityManager->getConnection()->getTransactionIsolation();
$entityManager->getConnection()->setTransactionIsolation(\Doctrine\DBAL\TransactionIsolationLevel::SERIALIZABLE);
$entityManager->beginTransaction();
try {
// do something...
$entityManager->flush();
$entityManager->commit();
} catch (\Exception $e) {
$entityManager->rollback();
throw $e;
} finally {
$entityManager->getConnection()->setTransactionIsolation($oldIsolationLevel);
}