Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "cannot refresh user" error with symfony2 and doctrine

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

like image 966
Mirage Avatar asked Jul 20 '12 01:07

Mirage


3 Answers

"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."

This is not the answer to the question, but if someone googles the error message above (like I did) this is the top hit. And since I found my solution, I thought I'd share.

You will get this error if you remove the current user from the database and then try to redirect the user. (Which might seem like a silly mistake, but the error message sure isn't helping!) The solution is to simply clear out the session before you redirect.

$this->get('security.context')->setToken(null);
$this->get('request')->getSession()->invalidate();
like image 64
ippi Avatar answered Nov 05 '22 09:11

ippi


From the code of EntityUserProvider.php it seems that you have to serialize id of the user also.

like image 5
Mun Mun Das Avatar answered Nov 05 '22 10:11

Mun Mun Das


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.

like image 1
laney Avatar answered Nov 05 '22 11:11

laney