If you have only $batchSize - 1 rows (amongst other cases), the entities are never flushed, you need a final flush outside the loop. In the bulk insert you should also need a final flush if the number of entities inserted is not a multiple of the $batchSize.
Doctrine 2 ORM
Doctrine 2 is an object-relational mapper (ORM) for PHP 5.3.2+ that provides transparent persistence for PHP objects. It sits on top of a powerful database abstraction layer (DBAL). One of its key features is the option to write database queries in a proprietary object oriented SQL dialect called Doctrine Query Language (DQL), inspired by Hibernates HQL. This provides developers with a powerful alternative to SQL that maintains flexibility without requiring unnecessary code duplication.
More resources:
Languages
PHP
100%