DtcQueueBundle icon indicating copy to clipboard operation
DtcQueueBundle copied to clipboard

Issue with Entity Manager when using in worker

Open mrvnklm opened this issue 6 years ago • 3 comments

Hey, I inject my entity manager into the worker via dependency injection and I receive following error when running the worker:

Detached entity Dtc\QueueBundle\Entity\Run@0000000078ced8230000000079c36310 cannot be removed

Is that because the bundle is using a different em? Actually I configured it to use the default orm.

EDIT: I figured out passing the class is not a problem, but inside the worker I need to use its own EntityManager like the following: public function getProducts(Customer $customer) { $customer = $this->entityManager->find('App:Customer', $customer->getId()); ...

Would that be the right way or should I pass the EM aswell?

mrvnklm avatar Jul 22 '18 12:07 mrvnklm

I'm issuing the same problem...any tips for this?

maikelreyes avatar Jan 18 '19 03:01 maikelreyes

@maikelreyes Well, I think I've learned that passing objects as argument isn't the best way to go. Especially if you switch from using ORM driven queue to RabbitMQ for example (which I would recommend due to performance and stability), you can't pass objects anymore and you should use IDs. So when I switched to IDs, I haven't had any issues like that anymore.

mrvnklm avatar Jan 18 '19 18:01 mrvnklm

Ok, I kind of understand what happens.

In my case I passed an entity object to the worker. Indeed the worker uses a different entity manager, because it's a different PHP process, it makes sense.

Not sure if "passing objects as argument isn't the best way to go", but indeed this can be very tricky, depending on what is passed on.

klodoma avatar Aug 26 '19 09:08 klodoma