Authenticated no after logged in issue in Symfony2

When you use custom entity with certain user table, Symfony2 will check token with inherited method. Especially, when User entity use refreshUser method, previous token and return object could be different value and profiler is displaying [Authenticated No].

One of solution is implementing EquatableInterface.

//in CustomUser Entity
class CustomUser implements UserInterface, EquatableInterface {
  public function isEqualTo(UserInterface $user){
    if($this->getId() == $user->getId()) return true;
    else return false;

Reverse engineering development with Symfony2

$ php app/console doctrine:mapping:convert xml ./src/Acme/DemoBundle/Resources/config/doctrine/metadata/orm --from-database --force

## add mapping unknown types
// Other connections parameters
oid: string


## generate Entities from DB
$ php app/console doctrine:mapping:import --em=foo AcmeDemoBundle annotation
## generate get//set method in Entity File
$ php app/console doctrine:generate:entities AcmeDemoBundle