My app has an entity called "client" that is injected into every request object.
To improve performance I've set up a custom cache, and am using JMSSerializer to serialize and cache client objects. When a request comes in, the cache returns the serialized Client object, and JMS deserializes it.
My application creates other entities, call them ChildEntities, and associates them with Client objects via a ManyToOne relationship on the ChildEntity.
This was working fine until I started loading these objects via deserializing the cached data, rather than using Doctrine to load them from the MySQL database. Doctrine now throws this error:
A new entity was found through the relationship "\acme\bundle\Entity\ChildEntity#client" that was not configured to cascade persist operations for entity: ClientName. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"})
So, if I'm understanding this error properly, it seems that Doctrine thinks my Client object which is referenced by a ManyToOne relationship on the ChildEntity object is a new object (even though I'm deserializing it with the ID) that it needs to save, but won't because no cascading is set up.
Is my strategy of deserializing objects wrong? Is there some way to deserialize them as Proxy objects, or some other solution to this problem? I prefer to use my custom cache to a doctrine cache.