title: Symfony 3 [Semantical Error] on authentication
body: <p>After some hours of search I can't find what I'm doing wrong, here my case:</p>
  
  <p>user entity:</p>
  
  <pre><code>/**
   * Many users belongs to one group
   *
   * @ORM\ManyToOne(targetEntity="Group", inversedBy="users")
   * @ORM\JoinColumn(name="user_group", referencedColumnName="id")
   *
   */
  private $group;
  </code></pre>
  
  <p>group entity:</p>
  
  <pre><code>/**
   * One group has many users
   * 
   * @ORM\OneToMany(targetEntity="User", mappedBy="group")
   */
  private $users;
  
  public function __construct()
  {
      $this-&gt;users = new ArrayCollection();
  }
  </code></pre>
  
  <p>When a visitor sign-up this is the method in the controller:</p>
  
  <pre><code>/**
   *
   * @Route("/signup", name="signup")
   *
   */
  public function signupAction(Request $request)
  {
  
      $data = $request-&gt;request-&gt;all();
      $user = new User();
      $form = $this-&gt;createForm(SignupType::class, $user);
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
  
          // Create account
          $account = new Account();
          $account-&gt;getCreatedby($user);
          $account-&gt;setCreateddate(new \DateTime("now"));
          $account-&gt;setName($form['username']-&gt;getData());
          $account-&gt;setIsActive(true);
  
          $user-&gt;setAccount($account);    // relate this account to the user
          $user-&gt;setCreateddate(new \DateTime("now"));
          $user-&gt;setLocale('en'); // Assign the locale
  
          // Encoding the password
          $password = $this-&gt;get('security.password_encoder')
              -&gt;encodePassword($user, $form['password']-&gt;getData());
          $user-&gt;setPassword($password);
  
          // Assign the group / role
          $group = $this-&gt;getDoctrine()-&gt;getRepository('AppBundle:Group')-&gt;findOneBy( array('name' =&gt; strtolower($form['user_type']-&gt;getData())) );
          //exit(\Doctrine\Common\Util\Debug::dump($group));
          $user-&gt;addGroup($group);
  
          // Persist objects to database
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $em-&gt;persist($account);
          $em-&gt;persist($user);
          $em-&gt;flush();
  
          return $this-&gt;render('default/show_message.html.twig', array(
              'alert_type' =&gt; 'success',
              'message' =&gt; 'You are registered',
              'redirect' =&gt; '',
          ));
      }
  
      return $this-&gt;render('security/signupForm.html.twig', array(
          'data' =&gt; $data,
          'form' =&gt; $form-&gt;createView(),
      ));
  
  }
  </code></pre>
  
  <p>This works nearly perfectly. The database is updated. But I noticed that in the field of user->group there is a null. When I uncomment the dump I see the right group data.</p>
  
  <p>So when the visitor tries to log-in I get this log:</p>
  
  <pre><code>[2017-04-11 20:04:41] request.INFO: Matched route "login". {"route":"login","route_parameters":{"_controller":"AppBundle\\Controller\\SecurityController::loginAction","_route":"login"},"request_uri":"http://test.com/app_dev.php/login","method":"POST"} []
  [2017-04-11 20:04:41] security.INFO: Authentication request failed. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AuthenticationServiceException(code: 0): [Semantical Error] line 0, col 60 near 'g WHERE u.username': Error: Class AppBundle\\Entity\\User has no association named groups at C:\\xampp\\htdocs\\test_com\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\Security\\Core\\Authentication\\Provider\\DaoAuthenticationProvider.php:94, Doctrine\\ORM\\Query\\QueryException(code: 0): [Semantical Error] line 0, col 60 near 'g WHERE u.username': Error: Class AppBundle\\Entity\\User has no association named groups at C:\\xampp\\htdocs\\test_com\\vendor\\doctrine\\orm\\lib\\Doctrine\\ORM\\Query\\QueryException.php:63, Doctrine\\ORM\\Query\\QueryException(code: 0): SELECT u, g FROM AppBundle\\Entity\\User u LEFT JOIN u.groups g WHERE u.username = :username OR u.email = :email at C:\\xampp\\htdocs\\test_com\\vendor\\doctrine\\orm\\lib\\Doctrine\\ORM\\Query\\QueryException.php:41)"} []
  [2017-04-11 20:04:41] security.DEBUG: Authentication failure, redirect triggered. {"failure_path":"login_failure"} []
  </code></pre>
  
  <p>So I'm sure I have a problem with the group field but unable to find out.</p>
  
  <p>Somebody to help me?. Thanks.</p>