mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Fix for BC break #7366 when calling EM::find() with LockMode::OPTIMISTIC outside of a TX
This commit is contained in:
committed by
Michael Moravec
parent
2f520244df
commit
ce76688865
@@ -904,7 +904,7 @@ final class EntityManager implements EntityManagerInterface
|
||||
if (! $class->isVersioned()) {
|
||||
throw OptimisticLockException::notVersioned($class->getClassName());
|
||||
}
|
||||
// Intentional fallthrough
|
||||
break;
|
||||
case LockMode::PESSIMISTIC_READ:
|
||||
case LockMode::PESSIMISTIC_WRITE:
|
||||
if (! $this->getConnection()->isTransactionActive()) {
|
||||
|
||||
78
tests/Doctrine/Tests/ORM/Functional/Ticket/GH7366Test.php
Normal file
78
tests/Doctrine/Tests/ORM/Functional/Ticket/GH7366Test.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\DBAL\LockMode;
|
||||
use Doctrine\ORM\Annotation as ORM;
|
||||
use Doctrine\ORM\TransactionRequiredException;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
|
||||
final class GH7366Test extends OrmFunctionalTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->setUpEntitySchema(
|
||||
[
|
||||
GH7366Entity::class,
|
||||
]
|
||||
);
|
||||
|
||||
$this->em->persist(new GH7366Entity('baz'));
|
||||
$this->em->flush();
|
||||
$this->em->clear();
|
||||
}
|
||||
|
||||
public function testOptimisticLockNoExceptionOnFind() : void
|
||||
{
|
||||
try {
|
||||
$entity = $this->em->find(GH7366Entity::class, 1, LockMode::OPTIMISTIC);
|
||||
} catch (TransactionRequiredException $e) {
|
||||
self::fail('EntityManager::find() threw TransactionRequiredException with LockMode::OPTIMISTIC');
|
||||
}
|
||||
self::assertEquals('baz', $entity->getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class GH7366Entity
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue
|
||||
* @var int
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Version
|
||||
*/
|
||||
protected $lockVersion = 1;
|
||||
|
||||
/**
|
||||
* @ORM\Column(length=32)
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName() : string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user