DDC-2586: BasicEntityPersister::_insertSql have old cached value, even if classmetadata changes #3246

Closed
opened 2026-01-22 14:16:33 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Aug 2, 2013).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user umed:

BasicEntityPersister caches *insertSql into the *insertSql property field. Its probably good, however I have a problem with it.

My class metadata can changed dynamically, and for example, if entity table has been changed, _insertSql value does not change.

For example, lets say I have such situation:

$entity = new MyEntity('somevalue');
$metadata = $entityManager->getClassMetadata('MyEntity');
$metadata->setPrimaryTable(array('name' => 'myentity_1'));
$entityManager->persist($entity); // here _insertSql is already cached with myentity_1 table name
$entityManager->flush();

$entity = new MyEntity('somevalue2');
$metadata = $entityManager->getClassMetadata('MyEntity');
$metadata->setPrimaryTable(array('name' => 'myentity_2'));
$entityManager->persist($entity); // here _insertSql DOES NOT CHANGE, even if class metadata has been changed, because its already cached and does not listens to the class metadata changes
$entityManager->flush();

// and the result I have 2 rows in the same myentity_1 table, but I want to have it in the different tables.

There is no method to clear **insertSql value, and no method to make it know about class metadata changes.
I want to see official solution for this problem

Originally created by @doctrinebot on GitHub (Aug 2, 2013). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user umed: BasicEntityPersister caches *insertSql into the *insertSql property field. Its probably good, however I have a problem with it. My class metadata can changed dynamically, and for example, if entity table has been changed, _insertSql value does not change. For example, lets say I have such situation: $entity = new MyEntity('somevalue'); $metadata = $entityManager->getClassMetadata('MyEntity'); $metadata->setPrimaryTable(array('name' => 'myentity_1')); $entityManager->persist($entity); // here _insertSql is already cached with `myentity_1` table name $entityManager->flush(); $entity = new MyEntity('somevalue2'); $metadata = $entityManager->getClassMetadata('MyEntity'); $metadata->setPrimaryTable(array('name' => 'myentity_2')); $entityManager->persist($entity); // here _insertSql DOES NOT CHANGE, even if class metadata has been changed, because its already cached and does not listens to the class metadata changes $entityManager->flush(); // and the result I have 2 rows in the same myentity_1 table, but I want to have it in the different tables. There is no method to clear **insertSql value, and no method to make it know about class metadata changes. I want to see official solution for this problem
admin added the Bug label 2026-01-22 14:16:33 +01:00
admin closed this issue 2026-01-22 14:16:34 +01:00
Author
Owner

@doctrinebot commented on GitHub (Aug 8, 2013):

Comment created by @FabioBatSilva:

You CANNOT change metadata on the fly.

If you really need to change metadata you can use implement a subscriber/listener listening to loadClassMetadata events..

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#lifecycle-events

@doctrinebot commented on GitHub (Aug 8, 2013): Comment created by @FabioBatSilva: You CANNOT change metadata on the fly. If you really need to change metadata you can use implement a subscriber/listener listening to loadClassMetadata events.. http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#lifecycle-events
Author
Owner

@doctrinebot commented on GitHub (Aug 8, 2013):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Aug 8, 2013): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3246