This problem will be difficult to reproduce for you, but I isolated the exact cause of it.
- Use any MetadataCache
- Create a complex entity with some inheritance. (I may detail in later if your really need it)
- Create an element of this entity with persist.
- Create an other element of this entity but not on the same php run. (ex: reload the page)
- The insert statement will fail because field names will not match parameters.
I narrowed it down to a serialization issue.
When you serialize an MetadataInfo, you don't serialize reflFields.
When you unserizlize you regenerate this value using ReflectionClass
That sound's like a good optimization.
The problem is that somehow, the reflection class can return the fields not in the same order that they were at the initial creation of the MetadataInfo.
Because the insertSql value is not re-generated, it can be out of sync with the new fields order.
The solution :
Call something like MetadataInfoFactory::_generateStaticSql (whish is private but ...) at wakeup time.