diff --git a/lib/Doctrine/ORM/OptimisticLockException.php b/lib/Doctrine/ORM/OptimisticLockException.php
index a1be1ec283e..2d507010585 100644
--- a/lib/Doctrine/ORM/OptimisticLockException.php
+++ b/lib/Doctrine/ORM/OptimisticLockException.php
@@ -8,6 +8,7 @@
use Doctrine\ORM\Exception\ORMException;
use Exception;
use RuntimeException;
+use Throwable;
/**
* An OptimisticLockException is thrown when a version check on an object
@@ -22,9 +23,9 @@ class OptimisticLockException extends Exception implements ORMException
* @param string $msg
* @param object|null $entity
*/
- public function __construct($msg, $entity)
+ public function __construct($msg, $entity, ?Throwable $previous = null)
{
- parent::__construct($msg);
+ parent::__construct($msg, 0, $previous);
$this->entity = $entity;
}
diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php
index 531b4c49ead..cf1d0898778 100644
--- a/lib/Doctrine/ORM/UnitOfWork.php
+++ b/lib/Doctrine/ORM/UnitOfWork.php
@@ -9,6 +9,7 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\EventManager;
use Doctrine\Common\Proxy\Proxy;
+use Doctrine\DBAL;
use Doctrine\DBAL\LockMode;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\Cache\Persister\CachedPersister;
@@ -433,11 +434,19 @@ public function commit($entity = null)
}
}
- // Commit failed silently
- if ($conn->commit() === false) {
+ $commitFailed = false;
+ try {
+ if ($conn->commit() === false) {
+ $commitFailed = true;
+ }
+ } catch (DBAL\Exception $e) {
+ $commitFailed = true;
+ }
+
+ if ($commitFailed) {
$object = is_object($entity) ? $entity : null;
- throw new OptimisticLockException('Commit failed', $object);
+ throw new OptimisticLockException('Commit failed', $object, $e ?? null);
}
} catch (Throwable $e) {
$this->em->close();
diff --git a/psalm.xml b/psalm.xml
index bcc5f1f6ff2..d806c8b2c4f 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -92,6 +92,8 @@
+
+