D
D
dinya172021-10-08 15:45:54
PHP
dinya17, 2021-10-08 15:45:54

Are there any peculiarities of how Doctrine works in long-lived applications?

I'm very interested in the answer to this question - Are there any peculiarities when working with Doctrine in a long-lived application?
There is a consumer who listens to the queue, when he receives something, he writes it to the database.
Before recording, it periodically makes queries to the database for reference information.

So, I spotted a feature. If the data in the database is changed by an SQL query, then the doctrine manager does not see this.
He seems to be ignoring the database. He does not see this changed data.
After restarting the consumer everything is ok.
How can this be?
The consumer lacks a parameter of some kind?
Or it is necessary to recreate connection before each request?

Who - niyuud faced similar?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maksim Fedorov, 2021-10-08
@dinya17

How can this be?

If you get an entity by id, then it is loaded once and then does not access the database, following changes in the entity from the application. I
suggest clearing the EM after each task processing through $em->clear()
Sometimes you want to clear the identity map of an EntityManager to start over. We use this regularly in our unit-tests to enforce loading objects from the database again instead of serving them from the identity map. You can call EntityManager#clear() to achieve this result.
https://www.doctrine-project.org/projects/doctrine...

Reading can be bypassed, it is better not to change entities bypassing EM
The consumer lacks a parameter of some kind?

It considers that you are working with the entity from the application, and not bypassing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question