Jira issue originally created by user psliwa:
When you persist and flush entity and then change id generator to AssignedGenerator (and id generator type to NONE) for this entity class and then you persist and flush new entity with assigned id, below error will occur:
Exception: [Doctrine\DBAL\Exception\DriverException] An exception occurred while executing 'INSERT INTO cms_emails (email) VALUES (?)' with params [13, "email@example.com"]:
SQLSTATE[HY000]: General error: 25 bind or column index out of range
There is test that reproduces this issue:
public function testPersistEntityAndThenSwitchToAssignedIdGenerator()
$email = new \Doctrine\Tests\Models\CMS\CmsEmail();
$email->email = 'firstname.lastname@example.org';
$classMetadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsEmail');
$id = 13;
$newEmail = new \Doctrine\Tests\Models\CMS\CmsEmail();
$newEmail->email = 'email@example.com';
$newEmail->id = $id;
$newEmail = $this->_em->find('Doctrine\Tests\Models\CMS\CmsEmail', $id);
The problem is in BasicEntityPersister* because insertSql is cached and is not cleared after changing id generator. Binded parameters count doesn't match with insert query because there is new parameter: *id.
Comment created by @ocramius:
Provided a possible fix at #942
Comment created by @doctrinebot:
A related Github Pull-Request [GH-942] was closed:
Comment created by @beberlei:
It is not a supported use case to change metadata after loading them.
Issue was closed with resolution "Invalid"