You may also run into a lazy loading exception if you hit an uninitialized association on the detached instance during the merge. By using an extending persistence context, entity instances don’t become detached.
Therefore, the persistence manager continues to track changes that are made to the entity.
This is called “Identity Map” pattern, which means Doctrine keeps a map of each entity and ids that have been retrieved per PHP request and keeps returning you the same instances.
In the previous example the echo prints “Hello World dude! You can even verify that Sometimes you want to clear the identity map of an Entity Manager to start over.
As Seam is a stateful framework, most use cases in Seam apps are modeled using conversational components.
In order to use a conversation, you must extend the persistence context.
You can walk all the associations inside your entity models as deep as you want.
Doctrine will not hold on to any references to detached entities. The synchronization involves writing any updates to persistent entities and their relationships to the database.
As a result the persistent state of such an entity will subsequently be properly synchronized with the database when method on an entity does NOT cause an immediate SQL INSERT to be issued on the database.
Doctrine applies a strategy called “transactional write-behind”, which means that it will delay most SQL commands until is invoked which will then issue all necessary SQL statements to synchronize your objects with the database in the most efficient way and a single, short transaction, taking care of maintaining referential integrity.
Note Generated entity identifiers / primary keys are guaranteed to be available after the next successful flush operation that involves the entity in question.
You can not rely on a generated identifier to be available directly after invoking After an entity has been removed its in-memory state is the same as before the removal, except for generated identifiers.
A real proxy class override all non-identity non-transient object state at instantiation time in order to enable lazy-loading mechanisms: Warning Traversing the object graph for parts that are lazy-loaded will easily trigger lots of SQL queries and will perform badly if used to heavily.