Flushed changes not rolling back #5334

Closed
opened 2026-01-22 15:04:47 +01:00 by admin · 3 comments
Owner

Originally created by @chinmayshah24 on GitHub (Nov 26, 2016).

Originally assigned to: @Ocramius on GitHub.

What is the real purpose of flush in doctrine? I am unable to use it in services properly. The changes are committed to the database regardless of any exceptions in processing. Should we just be using persist wrapped in a transactional block? This is my pseudo code:

$em->getConnection()->beginTransaction();
try{

    $q = new ABC\Entity\DEF();
    //fill it up...        
    $em->persist($q);
    $em->flush();

    throw new Exception("def");


} catch (Exception $ex) {

    $em->getConnection()->rollBack();
}

Same with the transactional closure. Basically the same as this approach in the docs. I mean it's there in the docs, and i am trying that. What am i doing wrong?

I don't even need to use commit. What's going on?

Is this a bug?

Originally created by @chinmayshah24 on GitHub (Nov 26, 2016). Originally assigned to: @Ocramius on GitHub. What is the real purpose of `flush` in doctrine? I am unable to use it in services properly. The changes are committed to the database regardless of any exceptions in processing. Should we just be using `persist` wrapped in a `transactional` block? This is my pseudo code: $em->getConnection()->beginTransaction(); try{ $q = new ABC\Entity\DEF(); //fill it up... $em->persist($q); $em->flush(); throw new Exception("def"); } catch (Exception $ex) { $em->getConnection()->rollBack(); } Same with the `transactional` closure. Basically the same as [this][1] approach in the docs. I mean it's there in the docs, and i am trying that. What am i doing wrong? I don't even need to use `commit`. What's going on? Is this a bug? [1]: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/transactions-and-concurrency.html#approach-2-explicitly
admin added the BugInvalid labels 2026-01-22 15:04:47 +01:00
admin closed this issue 2026-01-22 15:04:48 +01:00
Author
Owner

@Ocramius commented on GitHub (Nov 26, 2016):

The changes are committed to the database regardless of any exceptions in processing.

No, a transaction will be rolled back if an EntityManager#flush() fails: b06dcb89b3/lib/Doctrine/ORM/UnitOfWork.php (L402-L409)

Same goes for the EntityManager#transactional() API. You can find the implementation at b06dcb89b3/lib/Doctrine/ORM/EntityManager.php (L240-L245)

@Ocramius commented on GitHub (Nov 26, 2016): > The changes are committed to the database regardless of any exceptions in processing. No, a transaction will be rolled back if an `EntityManager#flush()` fails: https://github.com/doctrine/doctrine2/blob/b06dcb89b379252ebe26ed3913b2226a8fb8ebdd/lib/Doctrine/ORM/UnitOfWork.php#L402-L409 Same goes for the [`EntityManager#transactional()`](https://github.com/doctrine/doctrine2/blob/b06dcb89b379252ebe26ed3913b2226a8fb8ebdd/lib/Doctrine/ORM/EntityManagerInterface.php#L79-L80) API. You can find the implementation at https://github.com/doctrine/doctrine2/blob/b06dcb89b379252ebe26ed3913b2226a8fb8ebdd/lib/Doctrine/ORM/EntityManager.php#L240-L245
Author
Owner

@chinmayshah24 commented on GitHub (Nov 26, 2016):

My table was a MyISAM, as you suspected in the other thread

@chinmayshah24 commented on GitHub (Nov 26, 2016): My table was a MyISAM, as you suspected in the other thread
Author
Owner

@Ocramius commented on GitHub (Nov 26, 2016):

Discussion reference: https://github.com/doctrine/doctrine2/issues/5759#issuecomment-263044242

@Ocramius commented on GitHub (Nov 26, 2016): Discussion reference: https://github.com/doctrine/doctrine2/issues/5759#issuecomment-263044242
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5334