Getting "cannot refresh user" error with symfony2 and doctrine

Viewed 6735

I have the class User as the base class then i extended Teacher from user class.

When i try to login i get this error

You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine.

I have serialize/deserialize function in user.php as i have coped that from FOSUserbundle

public function serialize()
    {
        return serialize(array(
            $this->password,
            $this->salt,
            $this->usernameCanonical,
            $this->username,
            $this->expired,
            $this->locked,
            $this->credentialsExpired,
            $this->enabled,
        ));
    }

I am not able to find where i can check for error. i am stuck. please help

4 Answers

Just had the same issue using class table inheritance, it was caused by the visibility on the id property set to private, so the child class could not access the id, changing this to protected solved it.

The User object get's cloned at some point, so be sure to not do this (as I did):

function __clone()
{
    $this->id = null;
}
Related