in the flush procedure of entity manager, it seems changes will be committed at once when calling the flush function even I use the beginTransaction(). I am using doctrine/orm@dev-master
$conn = $em->getConnection();
$conn->beginTransaction();
try{
// $conn to delete existing data
// create $entity1
$em->persist($entity1);
$em->flush();
try{
// create $entity2
$em->persist($entity2);
// error in here and rollback to the beginning before taking any actions,
//however, it's not rolling back to the beginning point.
$em->flush();
$em->getConnection()->commit();
}catch(){
$em->getConnection()->rollBack();
}
$em->getConnection()->commit();
}catch(){
$em->getConnection()->rollBack();
}
@mamkkl could you log the queries being executed, and when? What sequence of queries did you expect?
@mamkkl I believe that's how it is supposed to work. flush() computes and sends all the INSERT/UPDATE/DELETE stuff out to the database, and only later (perhaps after other flushes) doe the commit() method-call send COMMIT to the database.
Are you saying that your changes went through even when there was a rollback?
Yes, what I am thinking is, once it reach an error and rollback in catch, the whole process should be rollback, even some flush() has been reached.
@mamkkl are you checking the changes at the DB level or inside your entities?
@Jean85 I am checking changes in DB level and found entities those were flush() successfully can't be rollback (records exist in DB).
@DHager So, I can't do CUD in a transaction via entities?
@mamkkl how were you able to get around this? I see this too
@mamkkl @chinmayshah24 maybe you are using a non-transactional storage engine? It is well known that MyISAM does not support transactions.
Oh yes. Legacy tables, didn't check that. Thanks @Ocramius
I can confirm this works.
Aaaaaaaand closing - please don't use MyISAM: it's a suicide.
Most helpful comment
Aaaaaaaand closing - please don't use MyISAM: it's a suicide.