Refresh and reload entities through session #6755

Open
opened 2026-01-22 15:38:03 +01:00 by admin · 0 comments
Owner

Originally created by @Cartman34 on GitHub (Jun 11, 2021).

Hello,

I am getting some trouble to maintain some code source with Doctrine entities through session.

While registering an user, he may register his enterprise with an establishment with an address, Also he may be having a personal address and in most cases, this address is the same than the establishment.
An address is unique in database, so we are re-using an existing entity if we find it in database.
All these entities may be persisted in session while using the wizard. Some of them can or can not be persisted in database, I can not predict it for all of them.

I keep db persisted entities in session to keep relations but in fact, it should be reloaded before each usage. To do that, I am using my own way with a simple find($id) and get the db object.
From manual, I thought EntityManager::refresh() may do the job but in fact no, it returns an error: "Undefined index: 000000004156b3a300000000288c6c93" while flushing (it seems the entity should be currently persisted)
When getting a flush error, all my session's entities are corrupted because they got an ID in PHP object but they are not persisted in database (Whaaat ?).

All this system is complex and I am not sure I am using Symfony & Doctrine in the right way.
What are the best practices in case of entities in session ? What should I do ?

Originally created by @Cartman34 on GitHub (Jun 11, 2021). Hello, I am getting some trouble to maintain some code source with Doctrine entities through session. While registering an user, he may register his enterprise with an establishment with an address, Also he may be having a personal address and in most cases, this address is the same than the establishment. An address is unique in database, so we are re-using an existing entity if we find it in database. All these entities may be persisted in session while using the wizard. Some of them can or can not be persisted in database, I can not predict it for all of them. I keep db persisted entities in session to keep relations but in fact, it should be reloaded before each usage. To do that, I am using my own way with a simple find($id) and get the db object. From manual, I thought EntityManager::refresh() may do the job but in fact no, it returns an error: "Undefined index: 000000004156b3a300000000288c6c93" while flushing (it seems the entity should be currently persisted) When getting a flush error, all my session's entities are corrupted because they got an ID in PHP object but they are not persisted in database (Whaaat ?). All this system is complex and I am not sure I am using Symfony & Doctrine in the right way. What are the best practices in case of entities in session ? What should I do ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6755