Actually, the entity should not know about EM. I use event listeners if I need some preliminary logic in my Entity. When you register Listeners like services, you can pass args there, such as EM or Container, and get them inside the Listener class.
Symfony doc
But I don't know if there is really a good way to get EM inside an Entity class. Accepting Kernel global variables in Entity methods.
global $kernel; if ( 'AppCache' == get_class($kernel) ) { $kernel = $kernel->getKernel(); } $em = $kernel->getContainer()->get( 'doctrine.orm.entity_manager' );
Shame on me: (
source share