I have this method in my service:
public function updateCountry($p_entity) {
var_dump($p_entity->getId()); //return 3 (as expected)
var_du
You shouldn't persist existing in DB entity, only new one. So if you get entity from DB and want to update it you should
Can you persist new entity at all?
If you can, try merging your object instead:
public function updateCountry($p_entity) {
var_dump($p_entity->getId()); //return 3 (as expected)
var_dump(get_class($p_entity) ); //return Country (as expected)
$this->em->merge($p_entity); // MERGE not PERSIST
$this->em->flush();
}
From official docs:
If X is a new entity instance, a new managed copy X’ will be created and the state of X is copied onto this managed instance.
So, basically, EntityManager::merge
can be used to both persist newly created object and merge exsistent one...